Forum Discussion
Range.Validation.Add problem with VBA
- Oct 20, 2024
The issue with using Range.Validation.Add in VBA often comes down to the way Excel interprets formulas when they are used in VBA. Specifically, formulas in VBA should always be written using English function names and with absolute references when necessary. Additionally, using the right syntax for specifying the range for validation is crucial.
Here's an attempted version of your VBA code with a fix for adding a custom validation rule using ISNUMBER, the English equivalent of ActualNumber.
Dim formel As String formel = "=ISNUMBER(A10)" With Columns("A:A").Validation .Delete .Add Type:=xlValidateCustom, AlertStyle:=xlValidAlertStop, Operator:=xlEqual, Formula1:=formel .IgnoreBlank = True .InCellDropdown = False .ErrorTitle = "Wert eingeben" .InputMessage = "" .ErrorMessage = "Der Wert muss eine Zahl sein." .ShowInput = False .ShowError = True End With
The VBA code is untested and serves as an example only, please backup your file in advance as a precaution.
My answers are voluntary and without guarantee!
Hope this will help you.
Was the answer useful? Mark as best response and Like it!
This will help all forum participants.
The issue with using Range.Validation.Add in VBA often comes down to the way Excel interprets formulas when they are used in VBA. Specifically, formulas in VBA should always be written using English function names and with absolute references when necessary. Additionally, using the right syntax for specifying the range for validation is crucial.
Here's an attempted version of your VBA code with a fix for adding a custom validation rule using ISNUMBER, the English equivalent of ActualNumber.
Dim formel As String
formel = "=ISNUMBER(A10)"
With Columns("A:A").Validation
.Delete
.Add Type:=xlValidateCustom, AlertStyle:=xlValidAlertStop, Operator:=xlEqual, Formula1:=formel
.IgnoreBlank = True
.InCellDropdown = False
.ErrorTitle = "Wert eingeben"
.InputMessage = ""
.ErrorMessage = "Der Wert muss eine Zahl sein."
.ShowInput = False
.ShowError = True
End With
The VBA code is untested and serves as an example only, please backup your file in advance as a precaution.
My answers are voluntary and without guarantee!
Hope this will help you.
Was the answer useful? Mark as best response and Like it!
This will help all forum participants.
using the englisch names is the solution.
Thank you very much for your help.
Manfred