匹配并连接vba

时间:2015-07-08 14:16:41

标签: excel vba excel-vba excel-formula multiple-matches

我有这样的数据

      A      B   C   D
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

NETVAT包含$Amount& 1,2等是行号& T1 / T5是TaxCodes

  

摘要列

      R        S      T
1. Customer  T5NET  T5VAT
2.  Sandy 
3.  Candy 
4.  Dandy 

我想在客户面前分别在摘要列中将NET + VATcell.address进行汇总。

  

示例:摘要列

       R        S      T
 1. Customer  T5NET  T5VAT
 2.  Sandy   =C3+C5  =D3+D5
 3.   etc

我假设我需要一个Match函数来匹配#1 Customer(汇总到数据库)和#2 T5然后将偏移值与汇总名称连接起来。

立即编辑(这很接近,但如何更改匹配功能呢?)

`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`

1 个答案:

答案 0 :(得分:0)

将所有内容向右推一列并放入A1“= B1& C2”。例如客户和T / C

然后在您的列中,您希望sum使用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”

,范围已超过一个