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

EXCEL在两个边框之间连接单元格中的所有文本,excel,string-concatenation,Excel,String Concatenation,在我的MS Excel电子表格中,边框用于确定某些相关数据的结尾。我想将这些相关单元格的内容转换为一个单元格。我想通过将列的单元格内的文本连接到边框,然后从下一个单元格开始,然后继续连接到下一个边框,依此类推。 这样做有什么诀窍吗? 提前谢谢你可以用这个做很多事情,但我认为你可以掌握窍门。 它是硬编码的,用于扫描第一列,并输出到第二列-显然,您可以对其进行参数化 Sub concat() ' loop on first column but this could be an input Di

在我的MS Excel电子表格中,边框用于确定某些相关数据的结尾。我想将这些相关单元格的内容转换为一个单元格。我想通过将列的单元格内的文本连接到边框,然后从下一个单元格开始,然后继续连接到下一个边框,依此类推。 这样做有什么诀窍吗?


提前谢谢

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

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

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

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

我相信这需要VBA。是的,我相信,但我是一名C#开发人员,不懂VisualBasic,我想我应该使用Excel Automation或Open XML SDKI。我相信这需要VBA。是的,我相信,但我是一名C#开发人员,不懂VisualBasic,我认为我应该使用Excel自动化或OpenXMLSDKWHY,而不应该使用UsedRange。。查看如何查找最后一行。。我不同意这一点——用代码创建的电子表格不应该有这个问题,只有当你开始编辑它-很明显,任何被触摸的单元格即使被删除也会成为最后一个单元格-这不是不可靠的,它提供了预期的行为-正如我所说的,根据使用情况,你可以用这个甚至硬编码100来做很多事情,如果你知道你将有100行,那么你应该避免使用。。查看如何查找最后一行。。我不同意这一点——用代码创建的电子表格不应该有这个问题,只有当你开始编辑它时——很明显,任何被触摸的单元格即使被删除也会变成最后一个单元格——这不是不可靠的,它提供了预期的行为——正如我所说的,根据使用情况,你可以用这个硬编码100做很多事情,以防你知道你将有100行