Sub test()
Dim a As Range
Set a = Range("A1")
Dim d()
d = Array(a.Offset(, 3).Value, a.Offset(, 4).Value, a.Offset(, 6).Value) '3個值
ReDim Preserve d(4) '多加兩個空間,保留 第1,2,3個值
d(3) = "4"
d(4) = "5"
End Sub作者: yangjie 時間: 2012-9-7 00:45
本帖最後由 yangjie 於 2012-9-7 00:47 編輯
回復 2#kimbal
感激Kimbal
問題為
default1 = wbf.Sheets("暫存").Cells(1, 5)
For i = 1 To 10
n1(i) = wbf.Sheets("暫存").Cells(i, 6)
If n1(i) = 0 Then
s1 = i - 1 's1匯出個數
Exit For
End If
Next
Dim d As Object
Dim a As Range
Set d = CreateObject("Scripting.Dictionary")
With Workbooks(str1).Sheets(sh1)
For Each a In .Range(.[2,default1], .[65536,default1].End(xlUp))
d(a & "") = Array(a.Offset(, n1(1)-default1).Value, a.Offset(, n1(2)-default1).Value] ,---共s1個)
Next
End With
應如何修改紅色那一行之語法?作者: yangjie 時間: 2012-9-7 02:54
回復 2#kimbal
感激Kimbal 2# 的教導
我另外用您的方法加一個 array d1( ) 以 d1(1),d1(2),d1(3)方式增加array內items
然後 d(a & "") = d1
解決了我的問題
如下
Dim d As Object
Dim a As Range
Set d = CreateObject("Scripting.Dictionary")
With Workbooks(str1).Sheets(sh1)
For Each a In .Range(.Cells(2, default1), .Cells(65536, default1).End(xlUp))
Dim d1()
d1 = Array(a.Offset(, n1(1) - default1).Value)
If s1 > 1 Then
For i = 2 To s1
ReDim Preserve d1(i - 1)
d1(i - 1) = a.Offset(, n1(i) - default1).Value
Next
End If
d(a & "") = d1
Next
End With
供大家參考指教
綜合多天來 在各帖指導
謝謝 Kimbal & Hsieh & GBKEE 三位大大