Excel VBA Data Validation Code

This is a generalised code for Excel VBA Data Validation. It can be used across sheets in a workbook.
Sub createValidation(rngValidation As Range, rngReference As Range) rngValidation.Validation.Delete rngValidation.ClearContents Dim strRefRange As String strRefRange = "=indirect(" & """" & "'" & rngReference.Parent.Name & "'!" & rngReference.Address & """" & ")" With rngValidation.Validation .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1:=strRefRange .IgnoreBlank = True .InCellDropdown = True .InputTitle = "" .ErrorTitle = "" .InputMessage = "" .ErrorMessage = "" .ShowInput = True .ShowError = True End With End Sub
»
- Vishesh's blog
- Add new comment
- 6044 reads

Recent comments
12 hours 11 min ago
19 hours 29 min ago
22 hours 22 min ago
22 hours 27 min ago
1 day 13 hours ago
1 day 13 hours ago
1 day 23 hours ago
2 days 15 hours ago
3 days 15 hours ago
3 days 15 hours ago