2017-08-25 19 views
0
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 

回答

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在變型的所有變量,

更改所有顯式聲明:

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 
+0

非常感謝 –

相關問題