0
輸入的數據將在下面的格式 -Excel的VBA基於多指標分析創建行組
+--------------------------------------+--------+---------+----------+
| Desc | Doc | Invoice | Order |
+--------------------------------------+--------+---------+----------+
| XXXXXXX;SFFFFFFFF;QQWEWEE;878dDDss11 | 98988 | 27891 | XXX32222 |
| XXXXXXX;SFFFFFFFF;QQWEWEE;878dDDss11 | 45444 | 422445 | # |
| XXX32222 | 4333 | 23444 | # |
| # | 4454 | 3345 | XXX32333 |
| # | 32333 | 44222 | ddh33333 |
| XXX32333 | 323222 | 45333 | # |
| XXX32333 | 322433 | 34333 | # |
| 4454 | 3333 | 232222 | # |
| XXXSDDD-ddh33333 | 34433 | 45555 | XX344444 |
+--------------------------------------+--------+---------+----------+
我希望有一個新的列,可以基於2個標準如下告訴團體 -
- 如果相同的價值在desc col,那麼行組將會像第1組,第2組相同
- 如果訂單或文檔或發票列值存在於Desc列然後行將屬於同一組
輸出將是 -
+--------------------------------------+--------+---------+----------+----------+
| Desc | Doc | Invoice | Order | Grouping |
+--------------------------------------+--------+---------+----------+----------+
| XXXXXXX;SFFFFFFFF;QQWEWEE;878dDDss11 | 98988 | 27891 | XXX32222 | Group 1 |
| XXXXXXX;SFFFFFFFF;QQWEWEE;878dDDss11 | 45444 | 422445 | # | Group 1 |
| XXX32222 | 4333 | 23444 | # | Group 1 |
| # | 4454 | 3345 | XXX32333 | Group 2 |
| # | 32333 | 44222 | ddh33333 | Group 3 |
| XXX32333 | 323222 | 45333 | # | Group 2 |
| XXX32333 | 322433 | 34333 | # | Group 2 |
| 4454 | 3333 | 232222 | # | Group 2 |
| XXXSDDD-ddh33333 | 34433 | 45555 | XX344444 | Group 3 |
+--------------------------------------+--------+---------+----------+----------+
到目前爲止,我已經試着寫下面的代碼
i = 0
For Each cell1 In Range("C5:C" & Cells(Rows.Count, "A").End(xlUp).Row).Cells
Debug.Print cell1.Row
jvno = cell1.Offset(0, 5).Value
invno = cell1.Offset(0, 6).Value
ordno = cell1.Offset(0, 7).Value
For Each cell3 In Range("C5:C" & Cells(Rows.Count, "A").End(xlUp).Row).Cells
Debug.Print cell3.Row
If ((cell1.Value = cell3.Value) And cell1.Value <> "#") Or InStr(cell3.Value, jvno) > 0 Or InStr(cell3.Value, invno) > 0 Or (InStr(cell3.Value, ordno) > 0 And (Not IsEmpty(ordno)) And ordno <> "#") Then
cell1.Offset(0, 18).Value = "Group " & i
cell3.Offset(0, 18).Value = "Group " & i
End If
Next cell3
i = i + 1
Next cell1
你到目前爲止嘗試過什麼? – Zac
編輯與我迄今嘗試過的問題 – baimzz