【问题标题】:Getting excel to put together split strings让excel将拆分字符串放在一起
【发布时间】:2014-09-03 22:17:12
【问题描述】:

我试图让 excel 将一系列尚未系统格式化的文本字符串放在一起,以便它们最终在数据表上分成不同的行。

我知道这可能已经在其他地方解决了,对此我深表歉意,但我很难描述这个问题,我无法在上面发布图片,但基本上是

  • 第 1 列包含条目列表,以及
  • 第 2 列包含分布在 2 行或更多行上的文本字符串

是否可以编写某种公式或宏来检查第一列,然后将第二列中的所有条目缝合在一起,直到在第一列中找到新条目?我有一种感觉,使用某种带有索引函数的循环可能是可能的,但我什至不知道从哪里开始。

谢谢, 迈克

【问题讨论】:

    标签: string excel text split


    【解决方案1】:

    迈克试一试

    子 appendValues()

    'sub 被设计为循环遍历代码,当有空值和列 a 时,它将获取 B 列中的值并附加到它上面的行并删除该行。

    将行暗淡为整数

    行 = 1

    '此代码从第一行开始,但可以随意更改。

    直到 ThisWorkbook.Sheets("sheet1").Cells(row, 2).Value = ""

    'loop语句被设计为继续循环直到你里面有一个空值第二列的值。

    If ThisWorkbook.Sheets("sheet1").Cells(row, 1).Value = "" Then

    ThisWorkbook.Sheets("sheet1").Cells(row - 1, 2).Value = ThisWorkbook.Sheets("sheet1").Cells(row - 1, 2).Value & ThisWorkbook.Sheets("sheet1" ).Cells(row, 2).Value

    行(行)。删除

    其他

    'else 语句是必需的,因为通过减少删除后的总行数存在隐含循环。

    行 = 行 + 1

    如果结束

    循环

    结束子

        Sub appendValues()
    'The sub is designed to loop through code and when ever there is a null value and column a it will take the value of what is in column B and appended to the row above it and delete the row.
    
    Dim row As Integer
    
    row = 1
    
    'This code starts with row one but this can be changed at will.
    
    Do Until ThisWorkbook.Sheets("sheet1").Cells(row, 2).Value = ""
    
    'loop statement is designed to continue to Loop until there is a null value inside of you the value in the second column.
    
    If ThisWorkbook.Sheets("sheet1").Cells(row, 1).Value = "" Then
    
    ThisWorkbook.Sheets("sheet1").Cells(row - 1, 2).Value = ThisWorkbook.Sheets("sheet1").Cells(row - 1, 2).Value & ThisWorkbook.Sheets("sheet1").Cells(row, 2).Value
    
    Rows(row).Delete
    
    Else
    
    'else statement is needed because there is an implied looping by decreasing the total number of rows after the delete.
    
    row = row + 1
    
    End If
    
    Loop
    
    End Sub
    

    【讨论】:

    • 迈克为你做了这个工作??还是您需要更多帮助?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多