PC Review


Reply
Thread Tools Rate Thread

copy unique values to validation list

 
 
buattis@anz.com
Guest
Posts: n/a
 
      26th Sep 2007
Hi all,

I've got a "backend" that looks like this:

Year
--------
2000
2000
2002
2000
2003
2004
2004
2001
2001

I'd like to create a range based on the unique values from this list
and then use this range to as validation list criteria for an input
cell in the "frontend" sheet. I know they could just auto-filter the
back end to select what year, but i don't want the users to touch the
backend.

Also, this backend will be updated constantly, so i need the range to
be redefined with every change.

Any ideas?

---
Stefano

 
Reply With Quote
 
 
 
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      26th Sep 2007
This is just an example that you can adapt to your needs. There are two
worksheets: frontend and backend.

Backend is your master list in column A starting in cell A2.

Frontend has the data validation list in column B starting in cell B1

The following macro automatically runs if you update the master list. It
examines the contents of the mater list and copies over all items except
duplicates and blanks. If the master list looks like:

Year
2001
2002
2002
2001
77
54
45
1
1
2
2001
77
3

then the copied list will be:

2001
2002
77
54
45
1
2
3


This macro is a worksheet event macro:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim skip_this_one As Boolean
Dim v() As Variant
Set t = Target
Set r = Range("A:A")
If Intersect(t, r) Is Nothing Then Exit Sub
n = Cells(Rows.Count, 1).End(xlUp).Row
ReDim v(n)

For i = 1 To n
v(i) = ""
Next
v(0) = Range("A2").Value
k = 1

For i = 2 To n
skip_this_one = False
x = Cells(i, 1).Value
If x = "" Then
skip_this_one = True
End If
For j = 0 To k
If x = v(j) Then
skip_this_one = True
End If
Next
If skip_this_one Then
skip_this_one = False
Else
v(k) = x
k = k + 1
End If
Next

Application.EnableEvents = False
Set sh = Sheets("frontend")
sh.Range("B:B").Clear
For i = 1 To k
sh.Cells(i, 2).Value = v(i - 1)
Next
Application.EnableEvents = True
End Sub


It goes in the worksheet code area, not a standard module.
--
Gary''s Student - gsnu2007


"(E-Mail Removed)" wrote:

> Hi all,
>
> I've got a "backend" that looks like this:
>
> Year
> --------
> 2000
> 2000
> 2002
> 2000
> 2003
> 2004
> 2004
> 2001
> 2001
>
> I'd like to create a range based on the unique values from this list
> and then use this range to as validation list criteria for an input
> cell in the "frontend" sheet. I know they could just auto-filter the
> back end to select what year, but i don't want the users to touch the
> backend.
>
> Also, this backend will be updated constantly, so i need the range to
> be redefined with every change.
>
> Any ideas?
>
> ---
> Stefano
>
>

 
Reply With Quote
 
buattis@anz.com
Guest
Posts: n/a
 
      27th Sep 2007
thanks Gary's Student

On Sep 27, 12:30 am, Gary''s Student
<GarysStud...@discussions.microsoft.com> wrote:
> This is just an example that you can adapt to your needs. There are two
> worksheets: frontend and backend.
>
> Backend is your master list in column A starting in cell A2.
>
> Frontend has the data validation list in column B starting in cell B1
>
> The following macro automatically runs if you update the master list. It
> examines the contents of the mater list and copies over all items except
> duplicates and blanks. If the master list looks like:
>
> Year
> 2001
> 2002
> 2002
> 2001
> 77
> 54
> 45
> 1
> 1
> 2
> 2001
> 77
> 3
>
> then the copied list will be:
>
> 2001
> 2002
> 77
> 54
> 45
> 1
> 2
> 3
>
> This macro is a worksheet event macro:
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> Dim skip_this_one As Boolean
> Dim v() As Variant
> Set t = Target
> Set r = Range("A:A")
> If Intersect(t, r) Is Nothing Then Exit Sub
> n = Cells(Rows.Count, 1).End(xlUp).Row
> ReDim v(n)
>
> For i = 1 To n
> v(i) = ""
> Next
> v(0) = Range("A2").Value
> k = 1
>
> For i = 2 To n
> skip_this_one = False
> x = Cells(i, 1).Value
> If x = "" Then
> skip_this_one = True
> End If
> For j = 0 To k
> If x = v(j) Then
> skip_this_one = True
> End If
> Next
> If skip_this_one Then
> skip_this_one = False
> Else
> v(k) = x
> k = k + 1
> End If
> Next
>
> Application.EnableEvents = False
> Set sh = Sheets("frontend")
> sh.Range("B:B").Clear
> For i = 1 To k
> sh.Cells(i, 2).Value = v(i - 1)
> Next
> Application.EnableEvents = True
> End Sub
>
> It goes in the worksheet code area, not a standard module.
> --
> Gary''s Student - gsnu2007
>
>
>
> "buat...@anz.com" wrote:
> > Hi all,

>
> > I've got a "backend" that looks like this:

>
> > Year
> > --------
> > 2000
> > 2000
> > 2002
> > 2000
> > 2003
> > 2004
> > 2004
> > 2001
> > 2001

>
> > I'd like to create a range based on the unique values from this list
> > and then use this range to as validation list criteria for an input
> > cell in the "frontend" sheet. I know they could just auto-filter the
> > back end to select what year, but i don't want the users to touch the
> > backend.

>
> > Also, this backend will be updated constantly, so i need the range to
> > be redefined with every change.

>
> > Any ideas?

>
> > ---
> > Stefano- Hide quoted text -

>
> - Show quoted text -



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Validation - List of unique values Oscar Microsoft Excel Misc 2 17th Feb 2010 01:59 PM
copy unique values into listbox, then modify sheet from these values Matthew Dyer Microsoft Excel Programming 4 28th Sep 2009 04:11 PM
Data Validation using Unique Values Hugh Microsoft Excel Misc 2 1st Jul 2009 04:10 PM
Need UNIQUE values for Data Validation List jg Microsoft Excel Programming 6 12th Apr 2006 10:42 PM
Copy unique values from 1 range in multiple worksheets to a list Joshua Powell Microsoft Excel Discussion 3 7th Jul 2004 01:20 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:59 PM.