vba 如何将字符串拆分为单独的单元格
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20644086/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to split string into separate cells
提问by user2991252
I have this string that consists of stockmarket data:
我有这个由股市数据组成的字符串:
162,90 1,10 0,67 162,80 163,00 164,30 162,80 157087560
What one can see is that there are 8 blocks of data in one string and that these blocks are separated with a space.
可以看到一个字符串中有8个数据块,这些数据块之间用空格隔开。
What I want to do is to split every block of data an place it into separate cells in Excel.
我想要做的是将每个数据块拆分到 Excel 中的单独单元格中。
回答by Eliezer Bernart
There is an option called "Text to columns", this will solve your problem. Using this tool it's possible to define what is your text delimiter (;
, ,
, and so on) or what is the size of your text block.
有一个名为“文本到列”的选项,这将解决您的问题。使用此工具可以定义文本分隔符(;
、,
等)或文本块的大小。
http://office.microsoft.com/en-001/excel-help/split-text-into-different-cells-HA102809804.aspx
http://office.microsoft.com/en-001/excel-help/split-text-into-different-cells-HA102809804.aspx
If you want a solution based on VBA script you can take a look at Excel Macro - Comma Separated Cells to Rows
如果您想要基于 VBA 脚本的解决方案,您可以查看Excel 宏 - 逗号分隔的单元格到行
回答by rheitzman
I had to think a bit on mehow's upper range eval. I came up with this for my useful snippets:
我不得不考虑一下 mehow 的上限评估。我为我的有用片段提出了这个:
For Each c In Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
' find last row in column A with data:
' from the bottom ("A" & Rows.Count)
' proceed Up to find last populated Cell in a given column (A)
Next c
For Each c In Range("A1:A" & Range("A1").End(xlDown).Row)
' from A1
' from top proceed down to row above the first unoccupied cell
Next c