返回列表 上一主題 發帖

[發問] 利用EXCEL巨集資料處理

[發問] 利用EXCEL巨集資料處理

如何修改以下宏, 把結果從欄位"訂貨單" 開始貼在result 上?

Sub nn()
Set d = CreateObject("Scripting.Dictionary")
Set d1 = CreateObject("Scripting.Dictionary")
With Sheet1
For Each a In .Range(.[A2], .[A65536].End(xlUp))
mystr = a.Offset(, 1) & a.Offset(, 2) & a.Offset(, 3) & a.Offset(, 4) & a.Offset(, 5)
  If IsEmpty(d(mystr)) Then
   ar = a.Resize(, 6).Value
   d(mystr) = a.Resize(, 6).Value
   d1(mystr) = 1
   Else
   ar = d(mystr)
   ar(1, 6) = ar(1, 6) + Val(a.Offset(, 5))
   d1(mystr) = d1(mystr) + 1
  End If
Next
End With
With Sheet2
  .[A2:G65536] = ""
  .[A2].Resize(d.Count, 6) = Application.Transpose(Application.Transpose(d.items))
  .[G2].Resize(d.Count, 1) = Application.Transpose(d1.items)
End With
End Sub

PICK.rar (11.41 KB)

已修改成這句, 可以達到目標, 但逐行貼上, 速度太慢, 可以簡化嗎

For i = 1 To D.Count
.Cells(1 + i, 1).Resize(1, 1) = Application.Transpose(Application.Transpose(D.items))(i, 4)
NEXT

TOP

試驗後. 都是 .Dictionary 較快, Split(Text, "-")<< 較耗時, 謝謝各大大!

TOP

        靜思自在 : 每天無所事事,是人生的消費者,積極、有用才是人生的創造者。
返回列表 上一主題