標題:
[發問]
依篩選條件輸出明細並統計
[打印本頁]
作者:
b9208
時間:
2012-9-30 21:42
標題:
依篩選條件輸出明細並統計
請教先進!
依附件檔中
〞LIST〞工作表中欄位〞物品〞(H)單項以〞+〞分開,且出貨時間(K)之日期及班別(P)相同,則只統計一筆資料。
篩選出之資料輸出於〞明細〞工作表中,並依「物品單項」及「日期」排序。
請參考附檔。
謝謝指導
[attach]12651[/attach]
作者:
Hsieh
時間:
2012-10-1 00:17
回復
1#
b9208
Sub ex()
Set dic = CreateObject("Scripting.Dictionary")
Set dic1 = CreateObject("Scripting.Dictionary")
Set dic2 = CreateObject("Scripting.Dictionary")
With Sheets("List")
For Each a In .Range(.[H6], .[H65536].End(xlUp)).SpecialCells(xlCellTypeConstants)
ar = Split(a, "+")
For Each c In ar
mystr = c & "," & Left(a.Offset(, 3), 8) & "," & a.Offset(, 8)
dic1(mystr) = Split(mystr, ",")
Next
Next
End With
With Sheets("明細")
ay = Application.Transpose(Application.Transpose(dic1.items))
For i = 1 To UBound(ay, 1)
mystr = ay(i, 1) & ay(i, 2)
dic2(ay(i, 1)) = dic2(ay(i, 1)) + 1
If IsEmpty(dic(mystr)) Then
ary = Array(ay(i, 1), ay(i, 2), 1)
Else
ary = dic(mystr)
ary(2) = ary(2) + 1
End If
dic(mystr) = ary
Next
With .[B3].Resize(dic.Count, 3)
.Value = Application.Transpose(Application.Transpose(dic.items))
.Sort key1:=.Cells(1, 1), header:=xlNo
For Each a In .Columns(1).Cells
If a <> a.Offset(-1, 0) Then a.Offset(, 3) = dic2(a.Value)
Next
End With
End With
End Sub
複製代碼
作者:
softsadwind
時間:
2012-10-1 15:48
回復
2#
Hsieh
謝謝 好用的想法 和解答
拾起 以後有機會可以用...
作者:
b9208
時間:
2012-10-1 22:05
回復
2#
Hsieh
非常感謝先進
執行可以使用
符合需求
再一次謝謝
另當〞List〞之H6以下欄位沒有資料時,則錯誤。
目前正研究如何排解,顯示通知並離開程式。
作者:
Hsieh
時間:
2012-10-1 22:35
回復
4#
b9208
Sub ex()
Set dic = CreateObject("Scripting.Dictionary")
Set dic1 = CreateObject("Scripting.Dictionary")
Set dic2 = CreateObject("Scripting.Dictionary")
With Sheets("List")
If .[H6].End(xlDown).Row = .Rows.Count Then MsgBox "無資料": Exit Sub '無資料
For Each a In .Range(.[H6], .[H65536].End(xlUp)).SpecialCells(xlCellTypeConstants)
ar = Split(a, "+")
For Each c In ar
mystr = c & "," & Left(a.Offset(, 3), 8) & "," & a.Offset(, 8)
dic1(mystr) = Split(mystr, ",")
Next
Next
End With
With Sheets("明細")
ay = Application.Transpose(Application.Transpose(dic1.items))
For i = 1 To UBound(ay, 1)
mystr = ay(i, 1) & ay(i, 2)
dic2(ay(i, 1)) = dic2(ay(i, 1)) + 1
If IsEmpty(dic(mystr)) Then
ary = Array(ay(i, 1), ay(i, 2), 1)
Else
ary = dic(mystr)
ary(2) = ary(2) + 1
End If
dic(mystr) = ary
Next
With .[B3].Resize(dic.Count, 3)
.Value = Application.Transpose(Application.Transpose(dic.items))
.Sort key1:=.Cells(1, 1), Header:=xlNo
For Each a In .Columns(1).Cells
If a <> a.Offset(-1, 0) Then a.Offset(, 3) = dic2(a.Value)
Next
End With
End With
End Sub
複製代碼
作者:
b9208
時間:
2012-10-3 11:32
回復
5#
Hsieh
Dear Hsieh,
非常感謝執行都ok
因資料筆數很多,所以查看SubTotal 資料不方便,
今想於〞明細〞工作表內[I3]輸出〞物品單項〞及[J3]輸出〞SubTotal〞。
懇請指導
謝謝
作者:
Hsieh
時間:
2012-10-3 17:54
回復
6#
b9208
Sub ex()
Set dic = CreateObject("Scripting.Dictionary")
Set dic1 = CreateObject("Scripting.Dictionary")
Set dic2 = CreateObject("Scripting.Dictionary")
With Sheets("List")
If .[H6].End(xlDown).Row = .Rows.Count Then MsgBox "無資料": Exit Sub '無資料
For Each a In .Range(.[H6], .[H65536].End(xlUp)).SpecialCells(xlCellTypeConstants)
ar = Split(a, "+")
For Each c In ar
mystr = c & "," & Left(a.Offset(, 3), 8) & "," & a.Offset(, 8)
dic1(mystr) = Split(mystr, ",")
Next
Next
End With
With Sheets("明細")
ay = Application.Transpose(Application.Transpose(dic1.items))
For i = 1 To UBound(ay, 1)
mystr = ay(i, 1) & ay(i, 2)
dic2(ay(i, 1)) = dic2(ay(i, 1)) + 1
If IsEmpty(dic(mystr)) Then
ary = Array(ay(i, 1), ay(i, 2), 1)
Else
ary = dic(mystr)
ary(2) = ary(2) + 1
End If
dic(mystr) = ary
Next
With .[B3].Resize(dic.Count, 3)
.Value = Application.Transpose(Application.Transpose(dic.items))
.Sort key1:=.Cells(1, 1), Header:=xlNo
For Each a In .Columns(1).Cells
If a <> a.Offset(-1, 0) Then a.Offset(, 3) = dic2(a.Value)
Next
End With
.[I3].Resize(dic2.Count, 1) = Application.Transpose(dic2.keys)
.[J3].Resize(dic2.Count, 1) = Application.Transpose(dic2.items)
End With
End Sub
複製代碼
作者:
b9208
時間:
2014-2-8 15:04
回復
7#
Hsieh
Dear Hsieh
增加篩選條件:List工作表C欄「單位」,符合明細工作表A 2 儲存格單位,才統計輸出資料。
如附件內紅色標示區
非常感謝指導
[attach]17452[/attach]
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)