Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Automatically update data validation list

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.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Automatically update data validation list

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").Ran ge("MyNames"), Target) = 0
Then
lReply = MsgBox("Add " & Target & " to list", vbYesNo +
vbQuestion)
If lReply = vbYes Then

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


Mike

" 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.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Automatically update data validation list

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

" 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.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Automatically update data validation list

On Jul 5, 8:23*pm, Mike H 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").Ran ge("MyNames"), Target) = 0
Then
* * * * * * * * * * lReply = MsgBox("Add " & Target & " to list", vbYesNo +
vbQuestion)
* * * * * * * * * * * * If lReply = vbYes Then

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

Mike



" 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!
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Automatically update data validation list

Hi,

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

Mike


" wrote:

On Jul 5, 8:23 pm, Mike H 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").Ran ge("MyNames"), Target) = 0
Then
lReply = MsgBox("Add " & Target & " to list", vbYesNo +
vbQuestion)
If lReply = vbYes Then

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

Mike



" 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!



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Automatically update data validation list

On Jul 5, 10:45*pm, Mike H wrote:
Hi,

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

Mike



" wrote:
On Jul 5, 8:23 pm, Mike H 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").Ran ge("MyNames"), Target) = 0
Then
* * * * * * * * * * lReply = MsgBox("Add " & Target & " to list", vbYesNo +
vbQuestion)
* * * * * * * * * * * * If lReply = vbYes Then


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


Mike


" 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!- Hide quoted text -


- Show quoted text -


Hi Mike,
Thanks again! That worked!
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Validation lists update orginal cell with list update [email protected] Excel Worksheet Functions 3 July 11th 08 07:56 AM
How to automatically show list in a validation list? Roger L Excel Programming 5 July 31st 07 07:50 PM
Help required with VBA program to automatically enter data from a validation list. Syd Excel Programming 4 January 15th 07 07:22 AM
Update Validation List Sean Timmons Excel Discussion (Misc queries) 2 August 27th 06 04:26 PM
update data validation list with new entries?? cjtj4700 Excel Discussion (Misc queries) 10 December 12th 05 01:00 AM


All times are GMT +1. The time now is 07:08 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"