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!!
 

Some videos you may like

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

lo1ly

Board Regular
Joined
Jun 14, 2013
Messages
54
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
 

L. Howard

Well-known Member
Joined
Oct 16, 2012
Messages
4,514
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
 

mole999

Moderator
Joined
Oct 23, 2004
Messages
10,274
Office Version
2019, 2016, 2013
Platform
Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,095,176
Messages
5,442,836
Members
405,201
Latest member
kashyap44

This Week's Hot Topics

  • Copy entire row if CountA <>0 to another sheet
    [B]I want to copy entire row if CountA <>0 for column J7:AM7 (headers on J6:AM6) and so on till the last used cell is column D and paste the...
  • Select last used Row in Table
    I have created a Table in a Worksheet which is locked to prevent user errors and protect formula. Some of the cells require freetext entries which...
  • excel workbook: do not allow certain file name
    Hello all, Don't think this has ever been asked before, but how do I restrict file save [Before_Save Event] if the name of the file being saved...
  • fixing problem autofilter
    hello i need help about my code when i search by code in textbox it doesn't show anything this is my data [ATTACH type="full"...
  • “Weight”
    Hi, i’ve got a long sheet filled with weights such as kg,g,L & ml. i can build a formula to convert kg into g and liter into ml. How ever, my...
  • How to capitalize everything before a certain character?
    In column A, I have some text: Hello good day.mp3 Hello good day.flac etc. I'd like to capitalize everything before the period. I don't need the...
Top