我想找出3個不同範圍內的不同值(文本)。 我想我找到了一種在線方式,但它給了我一個錯誤。Excel VBA從多個範圍計數不同的值
這裏是代碼;
Dim MyDict As Object, MyCols As Variant, OutCol As String, LastRowXY_2 As Long
Dim XY_A As Variant, I_XY As Long, MyData_XY As Variant
Set MyDict = CreateObject("Scripting.Dictionary")
MyCols = Array("P", "S", "V")
OutCol = "AN"
For Each XY_A In MyCols
LastRowXY_2 = Worksheets(Ders_Sheet_Adi).Cells(Rows.Count, XY_A).End(xlUp).Row
MyData_XY = Worksheets(Ders_Sheet_Adi).Range(XY_A & "22:" & XY_A & LastRowXY_2).Value
For I_XY = 1 To UBound(MyData_XY)
If MyData_XY(I_XY, 1) <> "" Then MyDict(MyData_XY(I_XY, 1)) = 1
Next I_XY
Next XY_A
Worksheets(Ders_Sheet_Adi).Range(OutCol & "1").Resize(MyDict.Count, 1).Value = WorksheetFunction.Transpose(MyDict.keys)
在「XY_A」的第二次運行中,MyData_XY給出了「類型不匹配」錯誤。
我可以使用任何形式的想法。
檢查什麼的'LastRowXY_2' –
在第二循環中的價值,LastRowXY_2的值是「22」 – Bildircin13
所以現在調試並查看「MyData_XY」(空) –