vba 将位于单元格中的逗号分隔字符串与列分开

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8995576/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 15:02:17  来源:igfitidea点击:

Separate a comma delimited string located in a cell to a column

excel-vbavbaexcel

提问by user793468

I have a comma delimited string (aad,adaa,,dadae,,,eresa,,baaa) in cell A1of Sheet1which I want to split and insert values in a column such as:

aad,adaa,,dadae,,,eresa,,baaa在单元格A1中有一个逗号分隔的字符串 ( ) Sheet1,我想在其中拆分并插入列中的值,例如:

aad
adaa

dadae


eresa

baaa

Empty values will skip a cell and insert the string in next cell.

空值将跳过一个单元格并在下一个单元格中插入字符串。

I am able to separate the string to a row but how could I do it to a column?

我能够将字符串分隔成一行,但我怎么能把它分成一列呢?

Here is my line to split the string to a row:

这是我将字符串拆分为一行的行:

Sheets("Sheet1").Range("A1").TextToColumns

回答by GSerg

Call WorksheetFunction.Transpose()after splitting to columns.

WorksheetFunction.Transpose()拆分为列后调用。

No need to use TextToColumnseither, Splitwill suffice:

也不需要使用TextToColumnsSplit就足够了:

Range("A1:A9").value = WorksheetFunction.Transpose(Split("aad,adaa,,dadae,,,eresa,,baaa", ","))