Text-to-column compile err

mkseto

New Member
Joined
Aug 14, 2018
Messages
38
Very new to macro, couldn't understand why I got compile error (syntax error) with the following:

Sub TextColumn()
Columns("A:A").Select
FieldInfo:=Array(Array(0, 1), Array(7, 1), Array(41, 1), Array(52, 1), Array(58, 1), _
Array(72, 1), Array(80, 1), Array(88, 1), Array(96, 1), Array(105, 1), Array(116, 1)), _
TrailingMinusNumbers :=True
End Sub

I originally had this:

Sub TextColumn()
Columns("A:A").Select
FieldInfo:=Array(Array(0, 1), Array(7, 1), Array(41, 1), Array(52, 1), Array(58, 1), Array(72, 1), Array(80, 1), Array(88, 1), Array(96, 1), Array(105, 1), Array(116, 1)), TrailingMinusNumbers :=True
End Sub

Got the same error, however.

This is probably some stupid mistake and obvious to most of you, so I'm sorry to waste your time, but would appreciate your help.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
You are missing quite a few parts of that function (including the actual Text to Columns part)!
If you turn on the Macro Recorder, and record yourself doing it manually, you will see what it should look like, for example:
Rich (BB code):
    Columns("A:A").Select
    Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
        FieldInfo:=Array(Array(0, 1), Array(4, 1), Array(8, 1)), TrailingMinusNumbers:= _
        True
It looks like you deleted the whole line in red above, you cannot do that!

You can shorten it by removing the "Select/Selection" like this:
Rich (BB code):
    Columns("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
        FieldInfo:=Array(Array(0, 1), Array(4, 1), Array(8, 1)), TrailingMinusNumbers:= _
        True
but you still need all the other pieces (TextToColumns, Destination. DataType, etc.

Your code should look something like this:
VBA Code:
    Columns("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
        FieldInfo:=Array(Array(0, 1), Array(7, 1), Array(41, 1), Array(52, 1), Array(58, 1), Array(72, 1), _
        Array(80, 1), Array(88, 1), Array(96, 1), Array(105, 1), Array(116, 1)), TrailingMinusNumbers :=True
 
Upvote 0
Solution
You are missing quite a few parts of that function (including the actual Text to Columns part)!
If you turn on the Macro Recorder, and record yourself doing it manually, you will see what it should look like, for example:
Rich (BB code):
    Columns("A:A").Select
    Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
        FieldInfo:=Array(Array(0, 1), Array(4, 1), Array(8, 1)), TrailingMinusNumbers:= _
        True
It looks like you deleted the whole line in red above, you cannot do that!

You can shorten it by removing the "Select/Selection" like this:
Rich (BB code):
    Columns("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
        FieldInfo:=Array(Array(0, 1), Array(4, 1), Array(8, 1)), TrailingMinusNumbers:= _
        True
but you still need all the other pieces (TextToColumns, Destination. DataType, etc.

Your code should look something like this:
VBA Code:
    Columns("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
        FieldInfo:=Array(Array(0, 1), Array(7, 1), Array(41, 1), Array(52, 1), Array(58, 1), Array(72, 1), _
        Array(80, 1), Array(88, 1), Array(96, 1), Array(105, 1), Array(116, 1)), TrailingMinusNumbers :=True
Thank you !!!!!
This is so obvious now, silly me, thanks again.
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,700
Members
448,979
Latest member
DET4492

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