Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 64
Default Validation Procedure with a worksheet change event

Hi All,

I am trying to change the validation of one cell based on the value of
another cell.

I have to following code that basically states that if cell "fPeriod" equals
"WEEK", then change the data validation of cell "fPeriodType" to a list
called "lstWeekNums".

Private Sub Worksheet_Change(ByVal Target As Range)

If Range("fPeriod") = "WEEK" Then

Range("fPeriodType").Clear
With Range("fPeriodType").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=Range("lstWeekNums")
.IgnoreBlank = True
.InCellDropdown = True
End With

End If
End Sub

I get an "Method 'Range' of object'_Worksheet' failed error.

Can anyone help please?

Thanks,

B/
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 10,593
Default Validation Procedure with a worksheet change event

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range("fPeriod")) Is Nothing Then

If Target.Value = "WEEK" Then

Range("fPeriodType").Clear
With Range("fPeriodType").Validation

.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:= _
xlBetween, Formula1:="=lstWeekNums"
.IgnoreBlank = True
.InCellDropdown = True
End With
End If
End If

ws_exit:
Application.EnableEvents = True
End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Bhupinder Rayat" wrote in
message ...
Hi All,

I am trying to change the validation of one cell based on the value of
another cell.

I have to following code that basically states that if cell "fPeriod"
equals
"WEEK", then change the data validation of cell "fPeriodType" to a list
called "lstWeekNums".

Private Sub Worksheet_Change(ByVal Target As Range)

If Range("fPeriod") = "WEEK" Then

Range("fPeriodType").Clear
With Range("fPeriodType").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=
_
xlBetween, Formula1:=Range("lstWeekNums")
.IgnoreBlank = True
.InCellDropdown = True
End With

End If
End Sub

I get an "Method 'Range' of object'_Worksheet' failed error.

Can anyone help please?

Thanks,

B/



  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 64
Default Validation Procedure with a worksheet change event

That works great, thanks Bob.

"Bob Phillips" wrote:

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range("fPeriod")) Is Nothing Then

If Target.Value = "WEEK" Then

Range("fPeriodType").Clear
With Range("fPeriodType").Validation

.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:= _
xlBetween, Formula1:="=lstWeekNums"
.IgnoreBlank = True
.InCellDropdown = True
End With
End If
End If

ws_exit:
Application.EnableEvents = True
End Sub

--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Bhupinder Rayat" wrote in
message ...
Hi All,

I am trying to change the validation of one cell based on the value of
another cell.

I have to following code that basically states that if cell "fPeriod"
equals
"WEEK", then change the data validation of cell "fPeriodType" to a list
called "lstWeekNums".

Private Sub Worksheet_Change(ByVal Target As Range)

If Range("fPeriod") = "WEEK" Then

Range("fPeriodType").Clear
With Range("fPeriodType").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=
_
xlBetween, Formula1:=Range("lstWeekNums")
.IgnoreBlank = True
.InCellDropdown = True
End With

End If
End Sub

I get an "Method 'Range' of object'_Worksheet' failed error.

Can anyone help please?

Thanks,

B/




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
workbook_Open event Procedure peerless Excel Discussion (Misc queries) 1 May 22nd 06 10:21 PM
workbook_Open event Procedure peerless Excel Discussion (Misc queries) 0 May 22nd 06 10:16 PM
Worksheet Change Event DCSwearingen Excel Discussion (Misc queries) 1 October 10th 05 10:25 PM
Worksheet Change Event TonyM Excel Discussion (Misc queries) 8 March 11th 05 12:52 PM
Worksheet Row Change event crazybass2 Excel Discussion (Misc queries) 4 December 8th 04 05:29 PM


All times are GMT +1. The time now is 01:32 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"