VBA COde To Parse Text to Column trouble

atf32

Board Regular
Joined
Apr 13, 2011
Messages
157
Have code that parses the text in a cell to columns (see below) It works well when the text is in one continual string.
example:
"July","September","October","November"

But when the data has a crlf separating each item, it does not work right. In such case, I only get the first result of "July".
example:
"July"
"September"
"October"
"November"

My Parse code:

Selection.TextToColumns Destination:=Range("E11"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:="""", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5 _
, 1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array( _
12, 1), Array(13, 1), Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1), _
Array(19, 1), Array(20, 1), Array(21, 1), Array(22, 1), Array(23, 1), Array(24, 1), Array( _
25, 1), Array(26, 1), Array(27, 1), Array(28, 1), Array(29, 1), Array(30, 1), Array(31, 1)) _
, TrailingMinusNumbers:=True

What can I do to handle both situations?
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
try
Code:
Selection.TextToColumns Destination:=Range("E11"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
Semicolon:=False, Comma:=[COLOR=#ff0000]True[/COLOR], Space:=False, Other:=True, OtherChar _
:=[COLOR=#ff0000]"" & Chr(10) & ""[/COLOR], FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5 _
, 1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array( _
12, 1), Array(13, 1), Array(14, 1), Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1), _
Array(19, 1), Array(20, 1), Array(21, 1), Array(22, 1), Array(23, 1), Array(24, 1), Array( _
25, 1), Array(26, 1), Array(27, 1), Array(28, 1), Array(29, 1), Array(30, 1), Array(31, 1)) _
, TrailingMinusNumbers:=True
 
Upvote 0
1601926435733.png

-- image restored --
 
Last edited by a moderator:
Upvote 0
Appreciate the response, but this only works for cases where the string includes the carriage returns. Apparently, I don't know when I will see cells that will include them or not.
 
Upvote 0
Appreciate the response, but this only works for cases where the string includes the carriage returns. Apparently, I don't know when I will see cells that will include them or not.
The code Fluff posted in Message #3 works correctly for me. Can you post an example cell content for which it did not work for you?
 
Upvote 0
In you op you showed values that were separated by commas, but in the test file, the first sample does not have commas.
Which is correct?
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top