Text import spilling over into new columns

jalea148

Board Regular
Joined
Mar 23, 2012
Messages
58
I'm importing several small 2 column data files of dates with variations of the following macro:
Sub ENPURP()
'
' ENPURP Macro
'

'
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and Settings\Administrator\My Documents\Dropbox\Files\P_EN_UR.CSV" _
, Destination:=Range("$AG$16"))
.Name = "P_EN_UR"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(3, 3)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub

After importing a few rows correctly the macro starts creating new columns and saves the data there.

The macro was captured using Data ==> From Text. This import ran ok.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
It looks like you set it to use both Tab and Comma as delimiters.
I would take a look at the data in your file, to see if you have some extra unintended delimiters in there that you weren't expecting.
 
Upvote 0
It looks like you set it to use both Tab and Comma as delimiters.
I would take a look at the data in your file, to see if you have some extra unintended delimiters in there that you weren't expecting.
Thanx for your suggestion.
I changed TextFileTabDelimiter = True to TextFileTabDelimiter = False and checked the text file for delimiters. There were none other than the commas. To insure there were no hidden characters, the file was opened with Notepad and resaved. The problem remains.
 
Upvote 0
There is no Attachment button, you would have to use the methods described in the link I provided. No matter, I can use the links you provided.

OK, I am looking at the files. Can you explain exactly what is happening?
When you run your code to import the test file your provided, where is it placing the data?
Are you overriding (or wanting to override) the old data starting in cell AG16?
Does it shift the existing data?
 
Upvote 0
There is no Attachment button, you would have to use the methods described in the link I provided. No matter, I can use the links you provided.

OK, I am looking at the files. Can you explain exactly what is happening?
When you run your code to import the test file your provided, where is it placing the data?
Are you overriding (or wanting to override) the old data starting in cell AG16?
Does it shift the existing data?
My intent was to overwrite to existing data. I just cleared the fields and ran the import - there were not any problems. Problem solved; thanx!
Can the macro be amended to allow overwriting of the existing data?
 
Upvote 0
You should be able to do what you did manually (clear the data first) and run the code. If you use the Macro Recorder, and record yourself performing that task, it will give you the code you need to do it automatically.

Let us know if you run into any problems.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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