標題:
[發問]
如何將相同的資料做整列數據的合併及加總
[打印本頁]
作者:
marklos
時間:
2012-1-16 21:23
標題:
如何將相同的資料做整列數據的合併及加總
本帖最後由 marklos 於 2012-1-16 21:24 編輯
請問如何將相同的資料作整列數據的合併~詳細需求如下
[attach]9227[/attach]
Sheet1 待處理工作表
將紅色標示內"F"欄位內數量為"0"的, 做整列刪除
將黃色標示內"F"欄位內數量不為"0"者 , 保留
將濾色標示內"A"欄位內資料相同者 , 做合併
[attach]9228[/attach]
Sheet2結果工作表, 需求結果如上圖所示
"F"欄位內數量為"0"的, 整列刪除
原本"A6&A7" 相同資料的欄位 , 其"D"&"G" 兩個欄位資料作合併
, "F" 欄位內的數量部份做加總.
[attach]9229[/attach]
煩請高人指點~
謝謝~
作者:
register313
時間:
2012-1-16 22:10
回復
1#
marklos
初學者VBA
Sub QQ()
LastRow = [A65535].End(xlUp).Row
For R = LastRow To [A1].Row Step -1
If Cells(R, "F") = 0 Then
Rows(R).Delete Shift:=xlUp
End If
If R = 1 Then Exit For
If Cells(R, "A") & Cells(R, "B") & Cells(R, "C") = Cells(R - 1, "A") & Cells(R - 1, "B") & Cells(R - 1, "C") Then
Cells(R - 1, "D") = Cells(R - 1, "D") & "/" & Cells(R, "D")
Cells(R - 1, "F") = Cells(R - 1, "F") + Cells(R, "F")
Cells(R - 1, "G") = Cells(R - 1, "G") & "," & Cells(R, "G")
Rows(R).Delete Shift:=xlUp
End If
Next
End Sub
複製代碼
作者:
Hsieh
時間:
2012-1-16 22:59
回復
1#
marklos
Sub ex()
Set d = CreateObject("Scripting.Dictionary")
With 工作表1
For Each a In .Range(.[A1], .[A1].End(xlDown))
If a.Offset(, 6) <> 0 Then
If IsEmpty(d(a.Value)) Then
d(a.Value) = Application.Transpose(Application.Transpose(a.Resize(, 9).Value))
Else
ar = d(a.Value)
ar(4) = ar(4) & "/" & a.Offset(, 3).Value
ar(6) = ar(6) + a.Offset(, 5).Value
ar(7) = ar(7) & "," & a.Offset(, 6).Value
d(a.Value) = ar
End If
End If
Next
End With
With 工作表2
.Cells = ""
.[A1].Resize(d.Count, 9) = Application.Transpose(Application.Transpose(d.items))
End With
End Sub
複製代碼
作者:
marklos
時間:
2012-1-17 11:07
回復
2#
register313
感謝您的幫忙~~
但是還有一事未明
其中"G"欄位資料作合併之後 , 是否可以再加以排序?
感恩~
作者:
register313
時間:
2012-1-17 15:58
回復
4#
marklos
回復
4#
GBKEE
感謝GBKEE完成修改
Sub QQ()
LastRow = [A65535].End(xlUp).Row
For RR = LastRow To [A1].Row Step -1
If Cells(RR, "F") = 0 Then
Rows(RR).Delete Shift:=xlUp
End If
If RR = 1 Then Exit For
If Cells(RR, "A") & Cells(RR, "B") & Cells(RR, "C") = Cells(RR - 1, "A") & Cells(RR - 1, "B") & Cells(RR - 1, "C") Then
Cells(RR - 1, "D") = Cells(RR - 1, "D") & "/" & Cells(RR, "D")
Cells(RR - 1, "F") = Cells(RR - 1, "F") + Cells(RR, "F")
Cells(RR - 1, "G") = Cells(RR - 1, "G") & "," & Cells(RR, "G")
Rows(RR).Delete Shift:=xlUp
End If
Next
Dim Rng As Range, Ar, xL As Integer, xW As String, R As Range
Set Rng = Sheets("Sheet1").[G1]
Do
xW = ""
If InStr(Rng, ",") Then
For xL = 1 To Len(Rng)
If Mid(Rng, xL, 1) Like "[A-z]" Then xW = xW & Mid(Rng, xL, 1) Else Exit For
Next
Ar = Split(Rng, ",")
With [IV1].Resize(UBound(Ar) + 1)
.Value = Application.Transpose(Ar)
.Cells.Replace xW, ""
.Sort Key1:=Range("IV1"), Order1:=xlAscending, Header:=xlNo
For Each R In .Cells
R = xW & R
Next
Rng = Join(Application.Transpose(.Value), ",")
.Value = ""
End With
End If
Set Rng = Rng.Offset(1)
Loop Until Rng(1) = ""
End Sub
複製代碼
作者:
marklos
時間:
2012-1-18 13:48
回復
5#
register313
感謝您的大力幫忙~~問題已經解決了!!!:P
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)