我刚刚创建了一个全新的宏。从互联网下面获取功能(所有学分都转到trumpexcel.com),代码在下面
Function CONCATENATEMULTIPLE(Ref As Range, Separator As String) As String
Dim Cell As Range
Dim Result As String
For Each Cell In Ref
Result = Result & Cell.Value & Separator
Next Cell
CONCATENATEMULTIPLE = Left(Result, Len(Result) - 1)
End Function
然后我继续从各个列中提取数据并放入其中(我的表是 20 行 x 10 列)
Sub conact_data()
Dim i As Integer
For i = 2 To Cells(Rows.Count, "A").End(xlUp).Row
Cells(i, "M").Value = Cells(i, "A").Value & " " & _
Cells(i, "B").Value & " / " & Cells(i, "D").Value & "; "
Next i
End Sub
多亏了这一点,我得到了 A、B 和 D 列的组合数据,所以它有 20 行。我现在要做的就是使用 CONCATENATEMULTIPLE 函数连接来自 M2:M21 的数据,因此我尝试了各种方法(我想要 P2 单元格中的这条大线),例如:
Cells(2, 16).Value = CONCATENATEMULTIPLE (M2:M21, " ")
或者
Range("P2") = "CONCATENATEMULTIPLE (M2:M21, " ")"
我真的不知道如何应用
其次,我想撤回Cells(i, "B").Value百分比。我可以在一行中这样做Cells(i, "B").NumberFormat="0.00%".Value(这显然对我不起作用)否则我需要将 B 列复制到具有数字格式的另一列中,然后合并新列,正确格式化而不是 B 列?
提前致谢