Last active
March 12, 2019 13:25
-
-
Save supergrass71/8d4b41af06e5c65145c26402be9cc978 to your computer and use it in GitHub Desktop.
[Cell Validation on the fly] Dynamically Add Data Validation to a Column of Cells #VBA #Excel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub AddValidation(cell as range) | |
'designed to work in tandem with worksheet function (see next) | |
If cell.rows.count>1 or cell.columns.count>1 then exit sub | |
With cell.validation | |
.delete | |
.add Type:=xlValidateList, AlertStyle:=xlValidateAlertStop, Operator: _ | |
xlBetween, Formula:="A,list,of,your,values" | |
.ignoreblank = True | |
.incelldropdown = true | |
end with | |
end sub | |
Private Sub Worksheet_SelectionChange(ByVal Target As Range) | |
Dim v as integer | |
v=0 | |
If not intersect(Target,Range("A;A")) is nothing then 'apply to your column | |
on error resume next | |
v = target.specialcells(xlcelltypesamevalidation).count | |
on error goto 0 | |
If v= 0 then | |
call AddValidation(target) | |
end if | |
end if | |
end sub | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment