If you get confused with setting the options of data validation, I will suggest "recording" a macro and diving into the codes there. For example, I just complete a sub to configure data validation for cells in a batch. Find the requirements and codes below.



Sub setCellDataValidation(idxRow As LongLong)
' column B
With Cells(idxRow, 2).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="E,PE,DE"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Input Format"
.InputMessage = "E/PE/DE"
.ErrorMessage = "Only E, PE, and DE allowed."
.IMEMode = xlIMEModeNoControl
.ShowInput = True
.ShowError = True
End With
' column D
With Cells(idxRow, 4).Validation
.Delete
.Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="0", Formula2:="100"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Input Format"
.InputMessage = "Integer in 0 - 100"
.ErrorMessage = "Only Integer in 0 - 100 allowed."
.IMEMode = xlIMEModeNoControl
.ShowInput = True
.ShowError = True
End With
' column E
With Cells(idxRow, 5).Validation
.Delete
.Add Type:=xlValidateDate, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="1/1/2022", Formula2:="12/31/2024"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Input Format"
.InputMessage = "yyyy-mm-dd in 2022/1/1 to 2024/12/31"
.ErrorMessage = "Only yyyy-mm-dd in 2022/1/1 to 2024/12/31 allowed."
.IMEMode = xlIMEModeNoControl
.ShowInput = True
.ShowError = True
End With
' column F
With Cells(idxRow, 6).Validation
.Delete
.Add Type:=xlValidateTime, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="00:00:00", Formula2:="23:59:59"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Time Format"
.InputMessage = "hh:mm in 00:00:00 to 23:59:59"
.ErrorMessage = "Only hh:mm in 00:00:00 to 23:59:59 allowed."
.IMEMode = xlIMEModeNoControl
.ShowInput = True
.ShowError = True
End With
' column W
With Cells(idxRow, 23).Validation
.Delete
.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertStop, Operator _
:=xlBetween, Formula1:="0.01", Formula2:="2000.99"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = "Input Format"
.InputMessage = "3 decimal"
.ErrorMessage = "Only 3 decimal allowed."
.IMEMode = xlIMEModeNoControl
.ShowInput = True
.ShowError = True
End With
End Sub
Hey can you please explain
'
again in a little detail, I just don't undersatnd what is "='" and "=!" ,I am new to VBA, please don't mind or if you have any link where I can study it in detail will be awesome.