PC Review


Reply
Thread Tools Rate Thread

Create validation list with Worksheet_change

 
 
LuisE
Guest
Posts: n/a
 
      28th Mar 2009
I have this code to place a validation list in cell A9 every time any cell
from A41 and down below changes. Then under if a value es selected i'll
change B9

Am I missing anythin? doesn't work

Private Sub Worksheet_Change(ByVal Target As Range)
''''''''''Creates validation list with month's dates
Dim r As Range, txt As String

If Target.Row > 40 And Target.Column = 1 Then
Application.EnableEvents = False
Application.ScreenUpdating = False
ActiveSheet.Unprotect

For Each r In Range("A41", Range("A" & Rows.Count).End(xlUp))
If Not IsEmpty(r) Then txt = txt & "," & r.Value
Next
With Range("A9")
.Value = Empty
With .Validation
.Delete
.Add Type:=xlValidateList, Formula1:=Mid$(txt, 2)
End With
.Select
End With

Range("B9").Value = ""


Application.EnableEvents = True
Application.ScreenUpdating = True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True,
AllowFiltering:=True


End If

If Target = Range("A9") Then
Range("B9") = WorksheetFunction.Text(ActiveSheet.Range("A9").Value, "DDD")
' DoIt
End If
End Sub


Thanks in advance
 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      28th Mar 2009
Hi

Unprotect sheet ect. at the top off the sub and protect ect. just
before end sub. I assume that column A is unlocked when the sheet is
protected...

Private Sub Worksheet_Change(ByVal Target As Range)
''''''''''Creates validation list with month's dates
Dim r As Range, txt As String

Application.EnableEvents = False
Application.ScreenUpdating = False
ActiveSheet.Unprotect

If Target.Row > 40 And Target.Column = 1 Then
For Each r In Range("A41", Range("A" & Rows.Count).End(xlUp))
If Not IsEmpty(r) Then txt = txt & "," & r.Value
Next
With Range("A9")
.Value = Empty
With .Validation
.Delete
.Add Type:=xlValidateList, Formula1:=Mid$(txt, 2)
End With
.Select
End With
Range("B9").Value = ""
End If

If Target = Range("A9") Then
Range("B9") = WorksheetFunction.Text(ActiveSheet.Range
("A9").Value, "DDD")
' DoIt
End If
Application.EnableEvents = True
Application.ScreenUpdating = True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True,
Scenarios:=True, AllowFiltering:=True
End Sub

Regerds,
Per

On 28 Mar., 03:14, LuisE <legonza...@yahoo.com> wrote:
> I have this code to place a validation list in cell A9 every time any cell
> from A41 and down below changes. Then under if a value es selected i'll
> change B9
>
> Am I missing anythin? * doesn't work
>
> Private Sub Worksheet_Change(ByVal Target As Range)
> *''''''''''Creates validation list with month's dates
> * * Dim r As Range, txt As String
>
> * * If Target.Row > 40 And Target.Column = 1 Then
> * * Application.EnableEvents = False
> * * Application.ScreenUpdating = False
> * * ActiveSheet.Unprotect
>
> * * For Each r In Range("A41", Range("A" & Rows.Count).End(xlUp))
> * * * * If Not IsEmpty(r) Then txt = txt & "," & r.Value
> * * Next
> * * With Range("A9")
> * * * * .Value = Empty
> * * * * With .Validation
> * * * * * * .Delete
> * * * * * * .Add Type:=xlValidateList, Formula1:=Mid$(txt, 2)
> * * * * End With
> * * * * .Select
> * * End With
>
> *Range("B9").Value = ""
>
> * * Application.EnableEvents = True
> * * Application.ScreenUpdating = True
> * ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True,
> AllowFiltering:=True
>
> * * End If
>
> If Target = Range("A9") Then
> * Range("B9") = WorksheetFunction.Text(ActiveSheet.Range("A9").Value,"DDD")
> ' *DoIt
> End If
> End Sub
>
> Thanks in advance


 
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
bug: Worksheet_Change clashes with dropdown list validation. Alfista71@SbcGlobal.net Microsoft Excel Programming 4 15th Jul 2009 12:58 AM
Runtime-error 1004 (excel 2007) when selecting validation list optiontriggering worksheet_change property Erik Microsoft Excel Programming 1 2nd Apr 2009 06:30 PM
data validation list does not trigger worksheet_change event =?Utf-8?B?aXZvcnlfa2l0dGVu?= Microsoft Excel Programming 1 17th Oct 2006 04:25 AM
Problem with Data Validation Dropdown List / Worksheet_Change Event wla6h@yahoo.com Microsoft Excel Programming 1 9th Aug 2006 10:21 PM
MS Bug? Data validation list dropdown with Worksheet_Change event Dan Frederick Microsoft Excel Programming 7 6th Apr 2004 05:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:35 AM.