View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Otto Moehrbach Otto Moehrbach is offline
external usenet poster
 
Posts: 1,090
Default Text to Columns in VBA

I see now that the macro will work with any number of text pieces regardless
of how many pieces of text were used in the recording. My question now is:
What is required in the macro and what isn't? Thanks for your time. Otto
"Otto Moehrbach" wrote in message
...
Excel 2002, WinXP
I am helping an OP with some VBA to manipulate some data. In the process
the code needs to do the Text-To-Columns task. I recorded the following
macro. The selection I chose has 7 pieces of comma separated text so this
macro works. But just on that entry. The actual entries have anything
from zero to ?? pieces of comma separated text. How do I code for a
varying number of comma separated text? Thanks for your time. Otto

Sub Macro2()
Selection.TextToColumns Destination:=Range("B2"),
DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False,
Tab:=False, _
Semicolon:=False, Comma:=True, Space:=False, Other:=False,
FieldInfo _
:=Array(Array(1, 2), Array(2, 1), Array(3, 1), Array(4, 1),
Array(5, 1), Array(6, 1), _
Array(7, 1)), TrailingMinusNumbers:=True
End Sub