VBA - "text to columns, delimitator = comma"

MetLife

Active Member
Joined
Jul 2, 2012
Messages
319
Office Version
  1. 365
Hi,

I'm recording a macro to do a text to columns command automatically. When I do this in record macro mode with a txt file I get the error message saying... "Too many line continuations".

Is there a way to get this to work? What code would i use?

Thanks,
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I am not clear on your requirement. If you open a comma-delimited file in Excel it automatically divides the text up into columns based on where the commas are. So I'm not clear on the scenario that you need a VBA solution for.

This code will take text in column A and split it into columns based on a comma delimiter (not delimitator). I don't know what you were trying to record.
VBA Code:
    Range("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, Comma:=True
 
Upvote 0
Solution
I am not clear on your requirement. If you open a comma-delimited file in Excel it automatically divides the text up into columns based on where the commas are. So I'm not clear on the scenario that you need a VBA solution for.

This code will take text in column A and split it into columns based on a comma delimiter (not delimitator). I don't know what you were trying to record.
VBA Code:
    Range("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, Comma:=True
Sorry, it was a ".txt" file. Not csv.
 
Upvote 0
I know you said the extension is .txt, but if it's comma-delimited you can change it to .csv.
 
Upvote 0
I created a comma-delimited file with a .txt extension, and when I opened it, Excel automatically converted the data into columns. I did not even get any prompts, it just opened like this.
VBA Code:
4.12,0.03,4.62,5.53,1,
,,,,,
375,,,,,1545
,,145,,,669.9
,,,,99,99


1727884903351.png
 
Upvote 0
I created a comma-delimited file with a .txt extension, and when I opened it, Excel automatically converted the data into columns. I did not even get any prompts, it just opened like this.
VBA Code:
4.12,0.03,4.62,5.53,1,
,,,,,
375,,,,,1545
,,145,,,669.9
,,,,99,99


View attachment 117598
open it up using the record macro feature. Go to File->open
you will be prompted to choose the type of delimiter before the file is loaded into excel.
 
Upvote 0
I don't see what you want to do. If you want to open this file, you don't need to use a macro. If you want to convert it after it's opened but data in one column, I provided code for that.

What do you need to do that is different than my suggestions so far? Do you want to open it automatically parsing it by commas, without having to see the delimiter dialog box? You would need additional code to prompt for the filename, then open it using code like what the macro generator did.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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