CONCATENATEfunction与dynamic范围

我想要一个dynamic范围的CONCATENATE函数。 范围可能非常不同,请参阅下面的示例。 是否有可能通过一个简单的代码来做到这一点?

例

范围仅用于行,其中列中非空单元格的数目不同。 我需要将每两个单元格配对,例如。

试试这个 – 您可能需要将C1更改为数据的开头

 Sub test() i = 0 i2 = 0 With ActiveSheet For Each cell In .Range("C1:" & .Range("C1").End(xlDown).Address) i2 = 0 temp = "" For Each c In .Range(.Cells(cell.Row, 3), .Cells(cell.Row, 3).End(xlToRight).Address) If i = 0 Then i = 1 Else 'every other column If i2 = 0 Then'first for each row needs no extra comma i = 0 temp = "(" & .Cells(cell.Row, -1 + c.Column).Value & "," & .Cells(cell.Row, 1 + c.Column).Value & ")" Else i = 0 temp = temp & ",(" & .Cells(cell.Row, -1 + c.Column).Value & "," & .Cells(cell.Row, c.Column).Value & ")" End If i2 = i2 + 1 End If Next .Cells(cell.Row, 1).Value = temp 'put string into column A Next End With End Sub