Excel VBA grouping string Function

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.