我有一系列选定的细胞。需要连接其中的所有列并将结果记录在行的第一个单元格中(选择中的第一列)。我正在尝试编写以下代码
Dim row As Object
Dim col As Object
Dim cell_concat As String
For Each row In Selection
cell_concat = ""
For Each col In row
cell_concat = cell_concat & col.Value
Next col
`How to record in first cell?
Next row
但遗憾的是,这种方法不起作用,我无法弄清楚如何在行的第一个单元格中记录cell_concat
。我做错了什么以及在代码中修复了什么?
答案 0 :(得分:1)
这会将值连接到所选的每一行的第一个单元格中:
Dim rw As Range
Dim col As Range
Dim cell_concat As String
For Each rw In Selection.Rows
cell_concat = ""
For Each col In rw.Cells
cell_concat = cell_concat & col.Value
Next col
rw.Cells(1, 1).Value = cell_concat
Next row