VB Text to column

lo1ly

Board Regular
Joined
Jun 14, 2013
Messages
54
I'm not sure what I'm doing wrong. I've tried multiple things and looked at different threads, but i still get the Run-time Error '1004'. I'm just trying to do text to column for range A:A in Sheet "LY".

This is the code I've been using

Code:
Sheets("LY").Select


            Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
        TextQualifier:=xlSingleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 1), TrailingMinusNumbers:=True

I've tried changing the range and messing with the other settings as well..


Any help is appreciated

Thanks!!
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Nevermind. I fixed it myself using a Dim. Thanks for looking though!

Code:
Dim objRange As Range


Set objRange = Range("A6:A350")






Sheets("LY").Activate


            objRange.TextToColumns _
                Destination:=Range("A6"), _
                DataType:=xlDelimited, _
                TextQualifier:=xlSingleQuote, _
                ConsecutiveDelimiter:=False, Tab:=False, _
                Semicolon:=False, _
                Comma:=True, _
                Space:=False, _
                Other:=False
 
Upvote 0
I can produce your error with your code if I do not select the data in column A. That is, I have the cursor sitting on a empty cell.

Your code wants a selection of comma delimited data to do its work. Which it does for me with data in A2:A10, and selected.

Maybe try this. No need to select.

Hoard

Code:
  Sheets("LY").Range("A2", Range("A2").End(xlDown)).TextToColumns Destination:=Range("A2"), DataType:=xlDelimited, _
        TextQualifier:=xlSingleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 1), TrailingMinusNumbers:=True
 
Upvote 0
This was just a short play with 5 values from two rows

Code:
    Range("A:A").Select
    Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=True, Space:=False, Other:=False, FieldInfo _
        :=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1)), _
        TrailingMinusNumbers:=True

I think you are selecting the sheet and then telling the vba to change a column, when its expecting a sheet

I'd be tempted to record one from the longest list you have, and potentially avoid trying to do that for a million rows
 
Upvote 0

Forum statistics

Threads
1,214,870
Messages
6,122,021
Members
449,060
Latest member
LinusJE

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