在Excel上自动清理此数据的最有效方法是什么?

时间:2017-11-02 15:21:29

标签: excel vba excel-vba

我是StackOverflow的新手,我正在寻找可以帮助我的人。我已经彻底搜索了网站,但我找不到问题的答案。

我正在寻找一种自动方式(可能是VBA)来清理下面的数据。我的问题是我要删除的文本内容和长度不规则,所以我不能应用常规公式,我需要一个复杂的公式,使我能够得到一些干净的数据。

以下是我遇到的数据摘录:

https://i.stack.imgur.com/ONObL.png

正如你在上面看到的那样,有两列,而在第二篇中,我想在大空间之后摆脱右侧的信息。

是否有公式可以删除此类文字?

1 个答案:

答案 0 :(得分:0)

Until I have an answer to my question in comment I shall give this answer

For RowCount = FirstRow to Lastrow
Activesheet.Cells(RowCount, 3).Value = Split(Activesheet.Cells(RowCount, 3).Value, "  ")(0)
Next RowCount

The way this works is it takes the value of the cell and Split() will use the delimiter " ", Double space, and replace the first value into the cell

You will need to specify the first & last row of which there are many examples of how to do online

=LEFT( A1, FIND( " ", A1 ) - 1 )

This is a formula of what you want as well it finds a double spacing and takes what is to the left of of the double spacing, the -1 removes the space left over at the end of the returned value