PC Review


Reply
Thread Tools Rate Thread

Automatically update data validation list

 
 
roniaelm@hotmail.com
Guest
Posts: n/a
 
      5th Jul 2008
Hello,

I need some help with setting up a data validation list that
automatically updates the data lsit. I am using the instructions and
VB code from this website: http://www.ozgrid.com/Excel/excel-va...ist-update.htm

Private Sub Worksheet_Change(ByVal Target As Range)

Dim lReply As Long

If Target.Cells.Count > 1 Then Exit Sub
If Target.Address = "$D$1" Then
If IsEmpty(Target) Then Exit Sub
If WorksheetFunction.CountIf(Range("MyNames"), Target)
= 0 Then
lReply = MsgBox("Add " & Target & " to list",
vbYesNo + vbQuestion)
If lReply = vbYes Then

Range("MyNames").Cells(Range("MyNames").Rows.Count + 1, 1) = Target
End If
End If
End If
End Sub

However, this code only works when the data list and the data
validation list are on the same worksheet. Can you help me adjust this
code so that the data list is on a seperate worksheet to the data
validation list.

Thanks for your help. My understanding of VB is very basic.

 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      5th Jul 2008
Hi,

When the range is on another sheet you must refer to the sheet

Private Sub Worksheet_Change(ByVal Target As Range)
Dim lReply As Long
If Target.Cells.Count > 1 Then Exit Sub
If Target.Address = "$D$1" Then
If IsEmpty(Target) Then Exit Sub
If
WorksheetFunction.CountIf(Worksheets("Sheet2").Range("MyNames"), Target) = 0
Then
lReply = MsgBox("Add " & Target & " to list", vbYesNo +
vbQuestion)
If lReply = vbYes Then

Worksheets("Sheet2").Range("MyNames").Cells(Worksheets("Sheet2").Range("MyNames").Rows.Count + 1, 1) = Target
End If
End If
End If
End Sub


Mike

"(E-Mail Removed)" wrote:

> Hello,
>
> I need some help with setting up a data validation list that
> automatically updates the data lsit. I am using the instructions and
> VB code from this website: http://www.ozgrid.com/Excel/excel-va...ist-update.htm
>
> Private Sub Worksheet_Change(ByVal Target As Range)
>
> Dim lReply As Long
>
> If Target.Cells.Count > 1 Then Exit Sub
> If Target.Address = "$D$1" Then
> If IsEmpty(Target) Then Exit Sub
> If WorksheetFunction.CountIf(Range("MyNames"), Target)
> = 0 Then
> lReply = MsgBox("Add " & Target & " to list",
> vbYesNo + vbQuestion)
> If lReply = vbYes Then
>
> Range("MyNames").Cells(Range("MyNames").Rows.Count + 1, 1) = Target
> End If
> End If
> End If
> End Sub
>
> However, this code only works when the data list and the data
> validation list are on the same worksheet. Can you help me adjust this
> code so that the data list is on a seperate worksheet to the data
> validation list.
>
> Thanks for your help. My understanding of VB is very basic.
>
>

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      5th Jul 2008
Hi,

You may also want to consider adding these 2 lines as the last 2 of your
subroutine. As data are added to the validation list these lines will re-size
the named range to ensure new data are added to the bottom each time

Set rng = Worksheets("Sheet2").Range("MyNames")
rng.Resize(rng.Rows.Count + 1).Name = "MyNames"

Mike

"(E-Mail Removed)" wrote:

> Hello,
>
> I need some help with setting up a data validation list that
> automatically updates the data lsit. I am using the instructions and
> VB code from this website: http://www.ozgrid.com/Excel/excel-va...ist-update.htm
>
> Private Sub Worksheet_Change(ByVal Target As Range)
>
> Dim lReply As Long
>
> If Target.Cells.Count > 1 Then Exit Sub
> If Target.Address = "$D$1" Then
> If IsEmpty(Target) Then Exit Sub
> If WorksheetFunction.CountIf(Range("MyNames"), Target)
> = 0 Then
> lReply = MsgBox("Add " & Target & " to list",
> vbYesNo + vbQuestion)
> If lReply = vbYes Then
>
> Range("MyNames").Cells(Range("MyNames").Rows.Count + 1, 1) = Target
> End If
> End If
> End If
> End Sub
>
> However, this code only works when the data list and the data
> validation list are on the same worksheet. Can you help me adjust this
> code so that the data list is on a seperate worksheet to the data
> validation list.
>
> Thanks for your help. My understanding of VB is very basic.
>
>

 
Reply With Quote
 
roniaelm@hotmail.com
Guest
Posts: n/a
 
      5th Jul 2008
On Jul 5, 8:23*pm, Mike H <Mi...@discussions.microsoft.com> wrote:
> Hi,
>
> When the range is on another sheet you must refer to the sheet
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> Dim lReply As Long
> * * If Target.Cells.Count > 1 Then Exit Sub
> * * * * If Target.Address = "$D$1" Then
> * * * * * * If IsEmpty(Target) Then Exit Sub
> * * * * * * * * If
> WorksheetFunction.CountIf(Worksheets("Sheet2").Range("MyNames"), Target) = 0
> Then
> * * * * * * * * * * lReply = MsgBox("Add " & Target& " to list", vbYesNo +
> vbQuestion)
> * * * * * * * * * * * * If lReply = vbYes Then
>
> Worksheets("Sheet2").Range("MyNames").Cells(Worksheets("Sheet2").Range("MyN*ames").Rows.Count + 1, 1) = Target
> * * * * * * * * * * * * End If
> * * * * * * * * End If
> * * * * End If
> End Sub
>
> Mike
>
>
>
> "ronia...@hotmail.com" wrote:
> > Hello,

>
> > I need some help with setting up a data validation list that
> > automatically updates the data lsit. I am using the instructions and
> > VB code from this website:http://www.ozgrid.com/Excel/excel-va...ist-update.htm

>
> > Private Sub Worksheet_Change(ByVal Target As Range)

>
> > Dim lReply As Long

>
> > * * If Target.Cells.Count > 1 Then Exit Sub
> > * * * * If Target.Address = "$D$1" Then
> > * * * * * * If IsEmpty(Target) Then Exit Sub
> > * * * * * * * * If WorksheetFunction.CountIf(Range("MyNames"), Target)
> > = 0 Then
> > * * * * * * * * * * lReply = MsgBox("Add " & Target & " to list",
> > vbYesNo + vbQuestion)
> > * * * * * * * * * * * * If lReply = vbYes Then

>
> > Range("MyNames").Cells(Range("MyNames").Rows.Count + 1, 1) = Target
> > * * * * * * * * * * * * End If
> > * * * * * * * * End If
> > * * * * End If
> > End Sub

>
> > However, this code only works when the data list and the data
> > validation list are on the same worksheet. Can you help me adjust this
> > code so that the data list is on a seperate worksheet to the data
> > validation list.

>
> > Thanks for your help. My understanding of VB is very basic.- Hide quoted text -

>
> - Show quoted text -


Hi Mike,

Thanks for your help it worked!!
Just one more thing, do you know how I can extend the target cells to
an entire column as I have data validation set for the whole column
and not just the single cell.

Thanks again!
 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      5th Jul 2008
Hi,

Instead of
If Target.Address = "$D$1" Then
use
If Not Intersect(Target, Range("D")) Is Nothing Then

Mike


"(E-Mail Removed)" wrote:

> On Jul 5, 8:23 pm, Mike H <Mi...@discussions.microsoft.com> wrote:
> > Hi,
> >
> > When the range is on another sheet you must refer to the sheet
> >
> > Private Sub Worksheet_Change(ByVal Target As Range)
> > Dim lReply As Long
> > If Target.Cells.Count > 1 Then Exit Sub
> > If Target.Address = "$D$1" Then
> > If IsEmpty(Target) Then Exit Sub
> > If
> > WorksheetFunction.CountIf(Worksheets("Sheet2").Range("MyNames"), Target) = 0
> > Then
> > lReply = MsgBox("Add " & Target & " to list", vbYesNo +
> > vbQuestion)
> > If lReply = vbYes Then
> >
> > Worksheets("Sheet2").Range("MyNames").Cells(Worksheets("Sheet2").Range("MyNÂ*ames").Rows.Count + 1, 1) = Target
> > End If
> > End If
> > End If
> > End Sub
> >
> > Mike
> >
> >
> >
> > "ronia...@hotmail.com" wrote:
> > > Hello,

> >
> > > I need some help with setting up a data validation list that
> > > automatically updates the data lsit. I am using the instructions and
> > > VB code from this website:http://www.ozgrid.com/Excel/excel-va...ist-update.htm

> >
> > > Private Sub Worksheet_Change(ByVal Target As Range)

> >
> > > Dim lReply As Long

> >
> > > If Target.Cells.Count > 1 Then Exit Sub
> > > If Target.Address = "$D$1" Then
> > > If IsEmpty(Target) Then Exit Sub
> > > If WorksheetFunction.CountIf(Range("MyNames"), Target)
> > > = 0 Then
> > > lReply = MsgBox("Add " & Target & " to list",
> > > vbYesNo + vbQuestion)
> > > If lReply = vbYes Then

> >
> > > Range("MyNames").Cells(Range("MyNames").Rows.Count + 1, 1) = Target
> > > End If
> > > End If
> > > End If
> > > End Sub

> >
> > > However, this code only works when the data list and the data
> > > validation list are on the same worksheet. Can you help me adjust this
> > > code so that the data list is on a seperate worksheet to the data
> > > validation list.

> >
> > > Thanks for your help. My understanding of VB is very basic.- Hide quoted text -

> >
> > - Show quoted text -

>
> Hi Mike,
>
> Thanks for your help it worked!!
> Just one more thing, do you know how I can extend the target cells to
> an entire column as I have data validation set for the whole column
> and not just the single cell.
>
> Thanks again!
>

 
Reply With Quote
 
roniaelm@hotmail.com
Guest
Posts: n/a
 
      5th Jul 2008
On Jul 5, 10:45*pm, Mike H <Mi...@discussions.microsoft.com> wrote:
> Hi,
>
> Instead of
> If Target.Address = "$D$1" Then
> use
> If Not Intersect(Target, Range("D")) Is Nothing Then
>
> Mike
>
>
>
> "ronia...@hotmail.com" wrote:
> > On Jul 5, 8:23 pm, Mike H <Mi...@discussions.microsoft.com> wrote:
> > > Hi,

>
> > > When the range is on another sheet you must refer to the sheet

>
> > > Private Sub Worksheet_Change(ByVal Target As Range)
> > > Dim lReply As Long
> > > * * If Target.Cells.Count > 1 Then Exit Sub
> > > * * * * If Target.Address = "$D$1" Then
> > > * * * * * * If IsEmpty(Target) Then Exit Sub
> > > * * * * * * * * If
> > > WorksheetFunction.CountIf(Worksheets("Sheet2").Range("MyNames"), Target) = 0
> > > Then
> > > * * * * * * * * * * lReply = MsgBox("Add " & Target & " to list", vbYesNo +
> > > vbQuestion)
> > > * * * * * * * * * * * * If lReply = vbYes Then

>
> > > Worksheets("Sheet2").Range("MyNames").Cells(Worksheets("Sheet2").Range("MyN**ames").Rows.Count + 1, 1) = Target
> > > * * * * * * * * * * * * End If
> > > * * * * * * * * End If
> > > * * * * End If
> > > End Sub

>
> > > Mike

>
> > > "ronia...@hotmail.com" wrote:
> > > > Hello,

>
> > > > I need some help with setting up a data validation list that
> > > > automatically updates the data lsit. I am using the instructions and
> > > > VB code from this website:http://www.ozgrid.com/Excel/excel-va...ist-update.htm

>
> > > > Private Sub Worksheet_Change(ByVal Target As Range)

>
> > > > Dim lReply As Long

>
> > > > * * If Target.Cells.Count > 1 Then Exit Sub
> > > > * * * * If Target.Address = "$D$1" Then
> > > > * * * * * * If IsEmpty(Target) Then Exit Sub
> > > > * * * * * * * * If WorksheetFunction.CountIf(Range("MyNames"), Target)
> > > > = 0 Then
> > > > * * * * * * * * * * lReply = MsgBox("Add " & Target & " to list",
> > > > vbYesNo + vbQuestion)
> > > > * * * * * * * * * * * * If lReply = vbYesThen

>
> > > > Range("MyNames").Cells(Range("MyNames").Rows.Count + 1, 1) = Target
> > > > * * * * * * * * * * * * End If
> > > > * * * * * * * * End If
> > > > * * * * End If
> > > > End Sub

>
> > > > However, this code only works when the data list and the data
> > > > validation list are on the same worksheet. Can you help me adjust this
> > > > code so that the data list is on a seperate worksheet to the data
> > > > validation list.

>
> > > > Thanks for your help. My understanding of VB is very basic.- Hide quoted text -

>
> > > - Show quoted text -

>
> > Hi Mike,

>
> > Thanks for your help it worked!!
> > Just one more thing, do you know how I can extend the target cells to
> > an entire column as I have data validation set for the whole column
> > and not just the single cell.

>
> > Thanks again!- Hide quoted text -

>
> - Show quoted text -


Hi Mike,
Thanks again! That worked!
 
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 lists update orginal cell with list update roniaelm@hotmail.com Microsoft Excel Worksheet Functions 3 11th Jul 2008 07:56 AM
Help required with VBA program to automatically enter data from a validation list. Syd Microsoft Excel Programming 4 15th Jan 2007 07:22 AM
update data validation list with new entries?? =?Utf-8?B?Y2p0ajQ3MDA=?= Microsoft Excel Misc 10 12th Dec 2005 01:00 AM
automatically update data validation selections dahill00 Microsoft Excel Misc 1 2nd Aug 2004 09:16 PM
Data Validation/Drop down list automatic update Dave Potter Microsoft Excel Misc 5 3rd Aug 2003 04:07 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:31 PM.