Sub Task()
Dim wb, wb1 As Workbook, copyrange, copyrange1, EWSD, Mrg1, Mrg2, Mrg3, Mrg4, SERange, SERange1 As Range, list, str, str1, str2, str3, str4 As String, Rowt As Long
Application.enableEvents = False
Set wb = ActiveWorkbook
list = Range("$A$15:$A$18")
With wb.Sheets("Client_Eligibility Info").Range("C16").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=list
End With
答案 0 :(得分:1)
Dim wb, wb1 As Workbook, copyrange, copyrange1, EWSD, Mrg1, Mrg2, Mrg3, Mrg4, SERange, SERange1 As Range, list, str, str1, str2, str3, str4 As String, Rowt As Long
将声明所有没有As
的变量作为变体
将all更改为显式声明:
Dim wb as workbook,wb1 as workbook,...
确保将list
声明为字符串
Dim list as String
然后将地址分配给变量:
'Make sure to assign the correct worksheet to this range
list = wb.WorkSheets("Sheet1").Range("$A$15:$A$18").Address
然后改变
Formula1:=list
一个公式。
Formula1:="=" & list
这样:
Sub Task()
Dim wb As Workbook, wb1 As Workbook
Dim copyrange As Range, copyrange1 As Range, EWSD As Range
Dim Mrg1 As Range, Mrg2 As Range, Mrg3 As Range, Mrg4 As Range
Dim SERange As Range, SERange1 As Range
Dim list As String, str As String, str1 As String, str2 As String
Dim str3 As String, str4 As String
Dim Rowt As Long
Application.EnableEvents = False
Set wb = ActiveWorkbook
list = wb.Worksheets("Sheet1").Range("$A$15:$A$18").Address
With wb.Worksheets("Client_Eligibility Info").Range("C16").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=" & list
End With