Hello !
I'm trying to dynamically modify Validation Lists in an Excel document but I bumped into an issue I have been trying to work out for days without success. :-(
The weird thing is that it works fine when I run the code as a macro but it notifies me with an error when I run it through an event ; such as a CommandButton1_Click() in this case.
Error notified on the ".Add Type:=..." line :
Run-time error '1004':
Application-defined or object-defined error
Code originally created by the Macro generator, and slightly modified afterwards :
The modification consist of : "Worksheets("Sheet1".Range("a1"" wich was originally : "Selection" .
Sub Macro1()
With Worksheets("Sheet1".Range("a1".Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="a,b,c,d,x21"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub
I even tried to copy and paste code from the Micrososft help example related to the "Validation object" and to run it, but it simply notified me an error at the same place on the line begining with ".Add ...".
I guess I should have missed some important concept in Visual Basic programmation, but I just can figure out what ???
Thanks in advance for your help if anybody has got an idea
I'm trying to dynamically modify Validation Lists in an Excel document but I bumped into an issue I have been trying to work out for days without success. :-(
The weird thing is that it works fine when I run the code as a macro but it notifies me with an error when I run it through an event ; such as a CommandButton1_Click() in this case.
Error notified on the ".Add Type:=..." line :
Run-time error '1004':
Application-defined or object-defined error
Code originally created by the Macro generator, and slightly modified afterwards :
The modification consist of : "Worksheets("Sheet1".Range("a1"" wich was originally : "Selection" .
Sub Macro1()
With Worksheets("Sheet1".Range("a1".Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="a,b,c,d,x21"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub
I even tried to copy and paste code from the Micrososft help example related to the "Validation object" and to run it, but it simply notified me an error at the same place on the line begining with ".Add ...".
I guess I should have missed some important concept in Visual Basic programmation, but I just can figure out what ???
Thanks in advance for your help if anybody has got an idea