您的位置:首页 > 编程语言 > VB

Excel VBA 分组 合并字符串函数

2008-12-10 09:43 435 查看
下载源文件 : http://lwl0606.cmszs.com/archives/excel-vba-string-function.html

在Excel 里面 如果要合并字符串可以用函数 =CONCATENATE(A4,B4,C4)

当然也可以 =A4 & B4 & C4

下面的函数可以实现分组合并字符串

第一个参数是分组的列,第二个是分组的内容,按照那个分组,第三个参数是同一分组内的排序列,第四个是要合并字符串的列

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) 得到结果aaaa;cccc;bbbb;

R1 tr
T1 tt
A1 aaaa
A9 bbbb
A3 cccc
b1 dddd
c1 eee
d1 xxx
d2 yyy
下载源文件 : http://lwl0606.cmszs.com/archives/excel-vba-string-function.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐