Importing CSV into existing non-active sheet.

Character7

New Member
Joined
Jul 15, 2017
Messages
7
I have fooled around with several different import VBA scripts I have seen littering the internet. I patch a couple together to get my desired result and am now pulling out my hair. For the love of peanut butter, please tell me what the heck is wrong with this portion of my import code?

With IncomingData.QueryTables.Add(Connection:= _
"TEXT;" & fStr, Destination:=IncomingData.Range("$A$1"))

*** Note, IncomingData is the name of the inactive sheet, the button which is activating this script is on a sheet called Dwelling.
*** Note, fStr as you may know is a reference to a function that opens a dialogue to choose said CSV from file system.

I just need to know how to clean this up so that when button is pressed on sheet "Dwelling", that it copies the CSV into sheet "IncomingData" starting at grid A1.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi Character7

Try:

Code:
With IncomingData.QueryTables.Add(Connection:= "TEXT;" & fStr, Destination:=[B]Sheets("[/B]IncomingData[B]")[/B].Range("$A$1"))

Cheers

pvr928
 
Upvote 0
I was able to get the result I was looking for using a combination of the information that you provided and a few other sources. My follow-up question is prior to importing the CSV, or during import, is it possible to modify this script to strip carriage returns before the information is loaded into the target worksheet? I have provided the code below which is attached to a clickable button within the workbook.

-----------------------------

Private Sub Import_Click()
Worksheets("IncomingData").Cells.Clear
With Worksheets("IncomingData").QueryTables.Add(Connection:= _
"TEXT;" & GetFile, Destination:=Worksheets("IncomingData").Range("$A$1"))
.Name = "logexportdata"
.FieldNames = False
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = False
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 2
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(xlGeneralFormat)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub

Function GetFile() As String
Dim filename__path As Variant
filename__path = Application.GetOpenFilename(FileFilter:="Csv (*.CSV), *.CSV", Title:="Select File To Be Opened")
If filename__path = False Then Exit Function
GetFile = filename__path
End Function
 
Upvote 0

Forum statistics

Threads
1,223,631
Messages
6,173,460
Members
452,516
Latest member
archcalx

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