EXCEL 连接两个边框之间单元格中的所有文本

EXCEL concatenate all text in cells between two borders

在我的MS Excel 电子表格中,Border 用于确定一些相关数据的结尾。我想将这些相关单元格的内容转换为一个单元格。我想通过连接列单元格内的文本直到 Border 并从下一个单元格开始并继续连接直到下一个 Border 等等来做到这一点。 . . . 这样做有技巧吗?

提前致谢

你可以用它做很多事情,但我认为你可以掌握它。 扫描第一列并输出到第二列是硬编码的——您显然可以对其进行参数化。

Sub concat()

' loop on first column but this could be an input
Dim max_rows As Integer
Dim start_col As Integer ' The column where your data is
start_col = 1
max_rows = ActiveSheet.UsedRange.Rows.Count ' count how many times to loop
Dim counter As Integer
counter = 1 ' this is for the output to know when we wrote out something we increment to next cell
Dim temp_string As String
temp_string = ""  ' variable to store until write out
For i = 1 To max_rows:
    Cells(i, 1).Select
    temp_string = temp_string + " " + ActiveCell.Value
    If Selection.Borders(xlEdgeBottom).LineStyle = 1 Then
        out = temp_string
        Cells(counter, 2) = out
        counter = counter + 1
        temp_string = ""
End If
Next i
End Sub