用VBA函数实现将某列单元格中值为1的对应的E列的文本拼接起来。
如下图所示,使用函数调用实现了F列和G列的处理。
Function ccc1(casename As String, flag As Range, info As Range) As String
If flag.Rows.Count <> info.Rows.Count Then
MsgBox "选定行数不同"
ccc1 = "error: line is diff"
Return
End If
If flag.Columns.Count <> 1 Then
MsgBox "选定flag列数不是1"
ccc1 = "error:select flagcol column is not 1"
Exit Function
End If
If info.Columns.Count <> 1 Then
MsgBox "选定info列数不是1"
ccc1 = "error: select info column is not 1"
Exit Function
End If
Dim res As String
For i = 1 To flag.Rows.Count Step 1
If flag(i, 1) = 1 Then
res = res & Chr(10) & info(i, 1)
End If
Next
ccc1 = res
End Function