Hi,
i have this code that i wrote in excel 2007
its work exelent but when i am trying to run the script in excel 2003 i got an error 1004
applocation defined or object defined error
this code change the datavalidation list dynamicly depands on a value in a cell
i hope that you can help me
shay
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$C$66" Then
If Range("CompBranch") = "áçø òðó" Or Range("CompBranch") = "" Then
Range("CompSubBranch").Select
Sheet1.Unprotect Password:="veryfunny!"
With Selection.Validation
.Delete
.Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
:=xlBetween
End With
Sheet1.Protect Password:="veryfunny!"
Range("CompSubBranch") = Empty
Exit Sub
End If
Call GenerateSubBranchList
Range("CompSubBranch") = "áçø úú òðó"
End If
End Sub
Sub GenerateSubBranchList()
Dim rng As String
rng = GetRange(Range("H66").Value)
Range("CompSubBranch").Select
Sheet1.Unprotect Password:="veryfunny!"
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="='List'!" & rng
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
Sheet1.Protect Password:="veryfunny!"
End Sub
Function GetRange(val As Integer) As String
Dim startPnt As Integer
Dim endPnt As Integer
For Each Item In Range("'List'!Q2:Q200")
If Item.Value = val And startPnt = Empty Then startPnt = Item.Row
If Item.Value = (val + 1) And endPnt = Empty Or Item.Value = Empty And endPnt =Empty Then endPnt = Item.Row - 1
Next
GetRange = "$P" & startPnt & ":$P" & endPnt
End Function
Bookmarks