Results 1 to 2 of 2

Adding a CSV file always adds an extra column

Threaded View

  1. #1
    Forum Contributor
    Join Date
    02-26-2012
    Location
    Ottawa, ON
    MS-Off Ver
    Excel 2007
    Posts
    129

    Adding a CSV file always adds an extra column

    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
    Last edited by NatalieEC; 12-18-2014 at 02:06 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Adding an extra column in a 2D array
    By j_Southern in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-24-2014, 07:27 AM
  2. [SOLVED] For Next Loop adds an extra #N/A?
    By mcclanat in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-15-2013, 06:01 PM
  3. [SOLVED] adding target lines into graphs without adding an extra column of data
    By ea223 in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 03-16-2013, 12:32 PM
  4. Replies: 2
    Last Post: 12-14-2010, 10:20 AM
  5. Help!! MailMerge Adds hidden extra page
    By petreli in forum Word Formatting & General
    Replies: 1
    Last Post: 12-14-2009, 08:55 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1