Hello,
I wrote some code that imports csv files into an excel sheet which works fine. I wrote the macro so that if it is clicked again, new files can be imported "on top" of the old files (deleted the csv range). My new problem is that it adds a new column after the csv file which I don't want. Initially I deleted the column in my code, but it does mess up some of my calculations regardless that weren't written using vba. I have my calculations two columns over from the last column of the csv file, but every time I run my code, it adds an additional column.
How do I get it to stop adding a new column?
Thanks!
Call deleteCSV
Dim fldr As FileDialog
Dim sItem As String
Dim path As String
Dim count As Integer
Dim ws As Worksheet
Dim i, n, m As Integer
Dim fileName As String
Dim newString As String
Dim label1 As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
Set ws = ThisWorkbook.ActiveSheet
label1 = "Reticle"
With fldr
.Title = "Select a Folder"
.ButtonName _
= "Select Path"
.AllowMultiSelect = False
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
n = 1
count = 0
m = 1
i = 1
path = sItem & "\*.csv"
fileName = Dir(path)
Do While fileName <> ""
count = count + 1
fileName = Dir()
Loop
fileName = InputBox("Type File Name Without Reticle Number")
While i <= count
newString = "TEXT;" & sItem & "\" & fileName & m & ".csv"
If Len(Dir((sItem & "\" & fileName & m & ".csv"))) <> 0 Then
With ws.QueryTables.Add(Connection:= _
newString _
, Destination:=Cells(10, n))
.Name = fileName & m
.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(1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
i = i + 1
Cells(1, n) = label1
Cells(1, n + 1) = m
n = n + 12
End If
m = m + 1
Wend
NextCode:
'GetFolder = sItem
Set fldr = Nothing
Bookmarks