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;
下载源文件 : 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;
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 |
相关文章推荐
- (转载)使用自定义聚集函数来实现分组合并字符串
- 编写函数void change(char *a,char *b,char*c)。 函数功能是首先把b指向的字符串逆向存放,然后将a指向的字符串和b指向的字符串按排列顺序交叉合并到c指向的数组中,两个字
- 自定义分组列值合并函数
- MSSQL 通过FOR XML PATH 模仿MYSQL的 group_concat 函数,將纪录值合并成字符串
- 编写函数void change(char *a,char *b,char*c)。 函数功能是首先把b指向的字符串逆向存放 然后将a指向的字符串和b指向的字符串按排列顺序交叉合并到c指向的数
- Mysql分组合并函数并进行数据列处理
- oracle,分组后,字符串以“,”合并
- 函数,聚合函数,分组,字符串连接
- Oracle: 四、函数,聚合函数,分组,字符串连接(中)
- 给出一个函数来合并两个字符串A和B。字符串A的后几个字节和字符串B的前几个字节重叠
- C语言合并字符串函数用法(strcat)
- 剑指offer2.3.2字符串:有两个排序的数组A1和A2,内存在A1的末尾有足够多的空余空间容纳A2,编写一个函数,将A2合并到A1并排序
- 用函数及sql语句合并字符串!
- sql 分组合并字符串字段 分享一个小技巧
- EXCEL中字符串连接或合并函数(CONCATENATE)
- SQL Server 2017新增:string_agg函数(分组合并字符串)
- MYSQL 分组合并函数
- 给出一个函数来合并两个字符串A和B
- MYSQL 分组合并函数
- WMSYS.WM_CONCAT(distinct(字段名)) 函数,字符串拼接函数。合并列