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
- hivishy's blog
- Add new comment
- 766 reads

Recent comments
8 hours 24 min ago
1 week 7 hours ago
1 week 7 hours ago
1 week 4 days ago
1 week 6 days ago
2 weeks 20 min ago
3 weeks 2 hours ago
4 weeks 3 days ago
4 weeks 3 days ago
4 weeks 6 days ago