问题
I am using the indirect function in my excel sheet through VBA , I am getting an error when I try to substitute the cell address in.
=indirect(F5)
I am not able to substiture the "F5" with a variable here is my code.
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=indirect(F5)"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
回答1:
Using a range
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=INDIRECT(""" & Range("F5").Address(False, False) & """)"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
来源:https://stackoverflow.com/questions/31455822/using-indirect-function-in-data-validation-through-vba