匹配并连接vba
我有这样的数据
ABCD 1. Customer T/C NET VAT 2. Sandy T1 3. Sandy T5 4. Sandy T1 5. Sandy T5 6. Candy T1 7. Candy T5 8. Dandy T5 9. Dandy T1
其中净值和VAT
包含$Amount
和1,2
等是行号和T1 / T5是TaxCodes
摘要列
RST 1. Customer T5NET T5VAT 2. Sandy 3. Candy 4. Dandy
我想分别在客户面前的Summary列中使用cell.address
来总结NET
+ VAT
。
示例:摘要列
RST 1. Customer T5NET T5VAT 2. Sandy =C3+C5 =D3+D5 3. etc
我假设我需要Match
函数来匹配#1 Customer
(数据库摘要)和#2 T5
然后将偏移值连接到汇总名称。
现在编辑(这是接近,但如何改变匹配function?)
`Sub MatchConcanate() Dim outputText As String, Rw As Range, cell As Range delim = "+" Application.ScreenUpdating = False Range("A:A").SpecialCells(xlCellTypeConstants).Select For Each Rw In Selection.Columns 'Here I want it to only Select Supplier till it is duplicate (they are sorted) and then to next For Each cell In Rw.Cells If cell.Value = "T5" Then outputText = outputText & delim & cell.Address End If Next cell With Rw 'Here I'd like a match function instead of pasting it all in cell 1 .Cells(1).Offset(0, 5).Value = outputText .HorizontalAlignment = xlGeneral .VerticalAlignment = xlCenter .WrapText = False End With outputText = "" Next Rw Application.ScreenUpdating = True End Sub`
把一切正确的一列,并放在A1“= B1和C2”。 例如客户和T / C
然后在你的列中,你想要sumif使用sumif
Name T1 T2 Sandy =SUMIF(A:A,S2&$T$1,D:D) =SUMIF(A:A,S2&$U$1,D:D) Candy =SUMIF(A:A,S3&$T$1,D:D) =SUMIF(A:A,S3&$U$1,D:D) Dandy =SUMIF(A:A,S4&$T$1,D:D) =SUMIF(A:A,S4&$U$1,D:D)
由于新的列“A”,范围已经移动了一个,