因此,我从工作表中获得了以下数据集:
+---------+-------------+-----------+
| Account | Type | Value |
+---------+-------------+-----------+
| XX | iPhone | 123 |
| XX | Samsung | 567 |
| XX | iPhone | 222 |
| BB | Samsung | 999 |
| CC | iPhone | 998 |
+---------+-------------+-----------+
我需要知道每个账户类型组合的价值。因此,我将帐户和类型复制到 B 列中的另一个工作表并连接帐户和类型。我删除了重复的之后
现在,我想像这样返回每个帐户的值并输入(在列中)。
+-----------+-----------+----------+-------------+----------+
| Account | Account | Type | Value 1 | Value 2 |
+-----------+-----------+---------+--------------+----------+
| XX-iPhone | XX | iPhone | 123 | 222 |
| XX-Samsung| XX | Samsung | 567 | |
| BB-Samsung| BB | Samsung | 999 | |
| CC-iPhone | CC | iPhone | 998 | |
+---------+-------------+------------------------+----------+
这是我的代码:
Dim Master as Worksheet, Filter as Worksheet
Dim lrow1 as Long
Set Master = Sheets("Master")
Set Filter = Sheets("Filter")
lrow1 = Master.range("A" & Rows.count).End(xlUp).row
Master.range("A2:B" & lrow1).copy
Filter.Range("B2").Pastespecial
'Copy info from Copy to Filter worksheet
Dim i as Integer, lrow2 as integer
lrow2 = Filter.Range("B" & Rows.count).End(xlUp).Row
With Filter
For i = 2 to lrow2
.Cells(i, 1) = .Cells(i ,2) & "-"& Cells(i, 3)
Next
End With
'Concatenate data
Dim lrow3 As Long
lrow3 = Filter.range("A" & Rows.Count).End(xlUp).Row
Filter.Range("A2:C" & lrow3).RemoveDuplicates Columns:=Array(1), Header:=xlYes
'Remove Duplicates
Dim lrow4 as long
lrow4= Filter.Range("A" & Rows.Count).End(xlUp).row
Dim rg as range
Set rg = Filter.Range("A2:A" & lrow4)
Dim i as Integer, j as integer
i = 2
j = 3
For Each cell in rg
If cell = Master.Cells(i,1)& "-" & Master.Cells(i,2) Then
cell.Offset(,j) = Master.Cells(i,3)
i = i + 1
j = j + 1
End if
Next
我似乎无法让它工作