When pasting text w/ VBA it puts it all in 1 column

WxShady13

Board Regular
Joined
Jul 24, 2018
Messages
184
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I am automatically extracting data out of a Text file and pasting it into Excel. When I do it puts all the columns from the Text file into Column A and you cannot easily separate them. I need to be able to keep the source formatting from the text file (i.e. Columns) when I paste. Any help is greatly appreciated.


Code:
Workbooks.OpenText Filename:=vFileName, _
    Origin:=xlMSDOS, StartRow:=1, DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, _
    ConsecutiveDelimiter:=False, Tab:=False, _
    Semicolon:=True, Comma:=True, Space:=False, _
    Other:=False, TrailingMinusNumbers:=True, _
    Local:=True
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
What's the column delimiter in the text file?
 
Upvote 0
Unfortunately there isn't really one...Here is some sample data but shows you how it is laid out.


12345 9224574 Doe, Jane W 08/27/2018 05:28:39 TSG011-EX
 
Upvote 0
If there isn’t one, how do you expect Excel to know what goes where? Is it fixed width?
 
Upvote 0
In the .TXT file there are separated columns. I want Excel to keep that formatting when it pastes.
 
Upvote 0
But how would it know that the first two spaces are column delimiters but the third and fourth are not? And what if some names don't have initials for example?
 
Upvote 0

Forum statistics

Threads
1,216,773
Messages
6,132,639
Members
449,739
Latest member
tinkdrummer

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