Import macro Bombs Out

ElvisHess

Board Regular
Joined
May 4, 2006
Messages
150
I have the following code that I use on a number of spreadsheets, For some reason on the latest one the macro bombs at the

With Selection.QueryTable

Line. Can anyone help me out?

Private Sub btnImportData_Click()
Me.Hide
Application.ScreenUpdating = True
Application.ScreenUpdating = False
Sheets("Info").Visible = True
Sheets("Info").Select
Range("H14,H11,N31:N32,G41").Value = Null 'Plant,Model Yr, EC Lvl, EC Date, Notes
Range("N13").Select 'False Word
Selection.Copy
Range("A25:A34").Select ' Report Selectors
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, skipblanks:=False, Transpose:=False
Range("N13").Select 'False Word
Selection.Copy
Range("W2:W17").Select ' Purchased Items Direct
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, skipblanks:=False, Transpose:=False
Range("N13").Select 'False Word
Range("W20:W44").Select ' Material Auto?
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, skipblanks:=False, Transpose:=False
Range("N13").Select 'False Word
Range("X20:X44").Select ' Steel or Aluminum?
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, skipblanks:=False, Transpose:=False
Range("A1").Select
Sheets("Info").Visible = False
Sheets("Fordtabs1").Visible = True
Sheets("Fordtabs1").Select
Range("M2").Value = Null 'Report Date
Range("A1").Select
Sheets("Fordtabs1").Visible = False
btnClear_Click 'Clears Import sheet
Application.ScreenUpdating = False
Sheets("Import").Visible = True
ChDrive "S"
ChDir "S:\PROJDATA\INITIAL\"
FileToOpen = Application _
.GetOpenFilename("Text Files (*.csv), *.csv") ' This grabs the whole file path
If TypeName(FileToOpen) = "Boolean" Then
Exit Sub
Else
Range("Info!m1").Value = FileToOpen 'This puts the file path into cell M1, then cell M2 chops it down.
connstring = "TEXT;" + FileToOpen
Sheets("Import").Select
With Selection.QueryTable
.Connection = connstring
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End If
btnFOMOCO
End Sub
 

Some videos you may like

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,374
What error is displayed? Does the sheet have a query table? Verify this by putting

MsgBox Sheets("Import").QueryTables.Count

before the With line.
 

ElvisHess

Board Regular
Joined
May 4, 2006
Messages
150
Its says 0 (zero) query tables. But none of my other spreadsheets have on either. I import the CSV file to populate customer documentation
 

ElvisHess

Board Regular
Joined
May 4, 2006
Messages
150
It appears that somehow I deleted a named range called Q1248 on the import sheet that was associated with a connection. The range for that was A1:Q271 I tried to rename that range and got an error telling me that the name doesn't start with a letter or is used somewhere else.

Any Tips?
 

ElvisHess

Board Regular
Joined
May 4, 2006
Messages
150
I fixed my name range on the import sheet, And its works. However I had to readjust any formula or reference to the import page, It moved them all to the right.

Thanks
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,663
Messages
5,512,717
Members
408,910
Latest member
fchri31

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top