2017-08-11 56 views
0

我使用這個宏腳本:Excel的類型匹配:

Dim lister As String 
Dim rowcounter As Integer 
Dim v As Variant 

rowcounter = ActiveWorkbook.Worksheets("1").Range("A2", Worksheets("1").Range("A2").End(xlDown)).Rows.Count 

For Each v In Range("A2:A" + rowcounter) 
lister = lister + "'" & CStr(v.Value) & "', " 
Next 

Debug.Print利斯特

這工作正常,到目前爲止,但給了我一個「類型不匹配錯誤」。

任何想法爲什麼?感謝你們!!

+0

使用&符號(&)代替加號(+)來連接。 – Domenic

回答

0

嘗試...

Dim sLister As String 
Dim rCell As Range 
Dim LastRow As Long 

With ActiveWorkbook.Worksheets("1") 
    LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row 
    For Each rCell In .Range("A2:A" & LastRow) 
     sLister = sLister & ", " & "'" & CStr(rCell.Value) & "'" 
    Next rCell 
End With 

sLister = Mid(sLister, 3) 

希望這有助於!