标题和值合并的Excel VBA函数
对于Excel中:
|-|A|B|C|
|--|--|
|1|品名|价格|重量|
|2|台灯|999|1.03Kg|
想变为:
品名: 台灯,
价格: 999,
重量: 1.03Kg,
开发了下面的函数:
Function joinTitleValue(name As Range, value As Range) As String
Dim result As String
result = ""
For i = 1 To name.Count
Dim v As String
v = Trim(CStr(value(i)))
If Len(v) <> 0 Then
result = result + name(i) + ": " + v + "," + Chr(10)
End If
Next
joinTitleValue = Left(result, Len(result) - 1)
End Function
使用时,在单元格中输入公式:
=joinTitleValue(A1:A3,B1:B3)
即可