4E6B 36A0 7DC2 E5F5 7B0E 724A AB
学到一招:Excel
http://jingyan.baidu.com/article/5d368d1e3ce69d3f60c057cf.html
/*
需要实现的目标如下:
要实现结果:在某个单元格中显示A列为张三的B列的合并,即为【30 43 42】
*/
参数a是要查找的区域,表示作为判断条件的区域,即判断资源区,如张三、李四、王五.....
参数b是提取数据的区域,表示需要汇总内容的区域,即显示资源区,如30 43 42
参数c是要查找的值,即查找信息区,表示“张三”
====================================
Sub loveyou(a As Range, b As Range, c As String)
Dim t As String
If a.Rows.Count <> b.Rows.Count Then abc = "错误": Exit Sub
For i = 1 To a.Rows.Count
If a.Cells(i, 1) = c Then t = t & " " & b.Cells(i, 1)
Next
abc = t
End Sub
====================================
Function abc(a As Range, b As Range, c As String)
Dim t As String
'如果a与b的区域大小不同,就显示“错误”
If a.Rows.Count <> b.Rows.Count Then abc = "错误": Exit Function
'在区域a是循环
For i = 1 To a.Rows.Count
'如果在a中找到与c相同的值,就把同一行中的b的内容提取出来,存入变量t中。
If a.Cells(i, 1) = c Then t = t & " " & b.Cells(i, 1)
Next
'将变量的值赋给自定义函数
abc = t
End Function
===================================