請問如何在多個工作表將要的資料顯示出來?,我找一個工作表可以顯示,但多個工作表
就不知道如何用陣列處理,煩請大大解惑!
With Sheets(c)
n = .[A65536].End(xlUp).Row
arr = .Range(.[A1], .Cells(n, 6))
ReDim arr2(1 To 5, 1 To UBound(arr)) '在程序層次中用來重新配置動態陣列變數的儲存空間
Set d = CreateObject("scripting.dictionary")
For i = 2 To n
chk = Mid(arr(i, 1), 1, 3) '對廠商編號做判定
If stcode = chk Then
x = arr(i, 4) - arr(i, 5)
b = Array(arr(i, 1), arr(i, 2), arr(i, 4), arr(i, 5), x)
If Not d.exists(arr(i, 1)) Then
M = M + 1
d(arr(i, 1)) = M
For j = 1 To 5
arr2(j, M) = b(j - 1)
Next
Else
For j = 3 To 5
arr2(j, d(arr(i, 1))) = arr2(j, d(arr(i, 1))) + b(j - 1)
Next
End If
Else
End If
Next
End With
[attach]7542[/attach][attach]7543[/attach]作者: flask 時間: 2011-8-22 15:16
sFName = "C:\資料庫\" & tdate & "月\" & stcok & "" & fdate & ".xls" ' 指定查找檔案路徑目錄"
Workbooks.Open Filename:=sFName, ReadOnly:=True ' 開檔
p = Sheets.Count
Do
With Sheets(p)
n = .[A65536].End(xlUp).Row
arr = .Range(.[A1], .Cells(n, 6))
ReDim arr2(1 To 5, 1 To UBound(arr)) '在程序層次中用來重新配置動態陣列變數的儲存空間
Set d = CreateObject("scripting.dictionary")
For i = 2 To n
chk = Mid(arr(i, 1), 1, 3)
If stcode = chk Then
x = arr(i, 4) - arr(i, 5)
b = Array(arr(i, 1), arr(i, 2), arr(i, 4), arr(i, 5), x)
If Not d.exists(arr(i, 1)) Then
M = M + 1
d(arr(i, 1)) = M
For j = 1 To 5
arr2(j, M) = b(j - 1)
Next
Else
For j = 3 To 5
arr2(j, d(arr(i, 1))) = arr2(j, d(arr(i, 1))) + b(j - 1)
Next
End If
Else
End If
Next
End With
On Error Resume Next
irow = wbook.[A65536].End(xlUp).Row
wbook.Range("A" & irow + 1).Resize(M, 5) = Application.Transpose(arr2)
p = p - 1: M = 0
Loop While p > 0
Application.DisplayAlerts = False
ActiveWorkbook.Close SaveChanges:=False
Sheets("Web").Activate
n = [A65536].End(xlUp).Row
arr = Range([A2], Cells(n, 6))
ReDim arr2(1 To 5, 1 To UBound(arr)) Set d = CreateObject("scripting.dictionary")
For i = 2 To n
b = Array(arr(i, 1), arr(i, 2), arr(i, 3), arr(i, 4), arr(i, 5))
If Not d.exists(arr(i, 1)) Then
M = M + 1
d(arr(i, 1)) = M
For j = 1 To 5
arr2(j, M) = b(j - 1)
Next
Else
For j = 3 To 5
arr2(j, d(arr(i, 1))) = arr2(j, d(arr(i, 1))) + b(j - 1)
Next
End If
請教好心的大大,我用這樣的方式處理有一個問題;
當廠商代碼有英文字的大小寫時會判斷是一樣,如985M與985m
會判斷是相同,不知是什麼原因?
With .Sheets(sh)
For Each a In .Range(.[a2], .[a2].End(xlDown))
stcode = Mid(a, 1, 2)
If stcode = mycode Then
Set b = wbook.Columns("e").Find(a, lookat:=xlWhole)
If b Is Nothing Then
wbook.Range("e" & l).Resize(, 2) = a.Resize(, 2).Value
wbook.Range("e" & l).Offset(, 2) = a.Offset(, 3).Value
wbook.Range("e" & l).Offset(, 3) = a.Offset(, 4).Value
l = l + 1
Else
b.Offset(, 2) = a.Offset(, 3).Value + b.Offset(, 2)
b.Offset(, 3) = a.Offset(, 4).Value + b.Offset(, 3)
End If
Else
End If
Next
End With作者: GBKEE 時間: 2011-8-31 20:07
回復 8#flask
MatchCase 選擇性的 Variant。若指定為 True,則搜尋時大小寫視為相異。預設值為 False。
Set b = wbook.Columns("e").Find(a, lookat:=xlWhole, MatchCase:=True)