获得excel汇总拆分字符串

时间:2014-09-03 22:17:13

标签: string excel text split

我正在努力将excel组合成一系列未系统格式化的文本字符串,以便它们最终分成数据表中的不同行。

我知道这可能已经在其他地方得到了解决,但很抱歉,但是我很难描述这个问题,而且我无法在其上发布图像,但基本上它是

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

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

谢谢, 麦克

1 个答案:

答案 0 :(得分:0)

迈克给了这个帖子

Sub appendValues()

&#39; sub设计用于循环遍历代码,当有空值和列a时,它将获取B列中的值并附加到其上方的行并删除该行。< / p>

Dim row As Integer

row = 1

&#39;此代码从第一行开始,但可以随意更改。

Do Until ThisWorkbook.Sheets(&#34; sheet1&#34;)。Cells(row,2).Value =&#34;&#34;

&#39;循环语句旨在继续循环,直到你内部的空值为第二列中的值。

如果ThisWorkbook.Sheets(&#34; sheet1&#34;)。Cells(row,1).Value =&#34;&#34;然后

ThisWorkbook.Sheets(&#34; sheet1&#34;)。Cells(row-1,2).Value = ThisWorkbook.Sheets(&#34; sheet1&#34;)。Cells(row-1,2) .Value&amp; ThisWorkbook.Sheets(&#34; sheet1&#34;)。Cells(row,2).Value

行(行).Delete

否则

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

row = row + 1

结束如果

循环

End Sub

    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
相关问题