Download source file: http://lwl0606.cmszs.com/archives/excel-vba-string-function.html
To merge strings in Excel, use the function = CONCATENATE (A4, B4, C4)
Of course, it can also be A4 & B4 & C4
The following function can merge strings by group.
The first parameter is the grouping column, the second is the grouping content, according to the grouping, the third parameter is the sorting column in the same group, and the fourth parameter is the column to merge strings
Function GT (GC As Range, G, SC As Range, VC As Range)
Dim vResult
Dim I As Integer
Dim J As Integer
Dim s As Integer
S = 0
Dim t As Integer
T = 1
Dim a () As Integer
Dim B () As String
For I = 1 To GC. Rows. Count
If GC. Item (I, 1) = G Then
S = s + 1
End If
Next I
ReDim a (s) As Integer
ReDim B (s) As String
For I = 1 To GC. Rows. Count
If GC. Item (I, 1) = G Then
A (t) = SC. cells (I, 1)
B (t) = VC. cells (I, 1)
T = t + 1
End If
Next I
For I = 1 To s
For J = I + 1 To s
If a (I)> a (J) Then
Temp = B (J)
B (J) = B (I)
B (I) = temp
Temp = a (J)
A (J) = a (I)
A (I) = temp
End If
Next J
Next I
For I = 1 To s
VResult = vResult & B (I )&";"
MsgBox a (0)
Next I
GT = vResult
End Function
= GT (A2: A10, A4, B2: B10, C2: C10). The results are aaaa, cccc, and bbbb;
R |
1 |
Tr |
T |
1 |
Tt |
A |
1 |
Aaaa |
A |
9 |
Bbbb |
A |
3 |
Cccc |
B |
1 |
Dddd |
C |
1 |
Eee |
D |
1 |
Xxx |
D |
2 |
Yyy |
Download source file: http://lwl0606.cmszs.com/archives/excel-vba-string-function.html