+ Reply to Thread
Results 1 to 5 of 5

CSV Import causing Header row to move columns

  1. #1
    Registered User
    Join Date
    06-13-2012
    Location
    Jacksonville, fl
    MS-Off Ver
    Excel 2007
    Posts
    4

    CSV Import causing Header row to move columns

    I am using the following code to prompt the loading of a csv file, pipe delimited into a worksheet that already has the headers defined in row A1. So the data from the csv file would be pasted into A2 and so on. This works for every fine every time I open excel for the first time. But if I try to load the file over and over without closing out excel, the header row actualy moves to the right one column to Col B. I delete that blank column (A) created and load again. Them next time, it moves the header row over 2 columns, then 4, then 8 etc... I recorded a macro to make sure the code I had was correct - the only diff was the value 1 instead of 2 for the TextFileColumnDataTypes - but that did not seem to make a differance. I am wodering if excel's cache is holding onto some value causing this to occur or if it could be the file? BC when I run the same code for a diff file (same csv pipe delimited but diff headers), it always works fine.

    With ActiveSheet.QueryTables.Add(Connection:= _
    "TEXT;" & USBL4fileToOpen _
    , Destination:=Range("$A$2"))
    .Name = "Input Seed"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = False
    .RefreshPeriod = 0
    .TextFilePromptOnRefresh = False
    .TextFilePlatform = 437
    .TextFileStartRow = 2
    .TextFileParseType = xlDelimited
    .TextFileTextQualifier = xlTextQualifierNone
    .TextFileConsecutiveDelimiter = False
    .TextFileTabDelimiter = False
    .TextFileSemicolonDelimiter = False
    .TextFileCommaDelimiter = False
    .TextFileSpaceDelimiter = False
    .TextFileOtherDelimiter = "|"
    .TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
    .TextFileTrailingMinusNumbers = True
    .Refresh BackgroundQuery:=False
    End With

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: CSV Import causing Header row to move columns



    Amend RefreshStyle

  3. #3
    Registered User
    Join Date
    06-13-2012
    Location
    Jacksonville, fl
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: CSV Import causing Header row to move columns

    I changed it to xlInsertEntireRows, closed out excel and tried again, and it did not help, it actually moved the header row on the first file load.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Re: CSV Import causing Header row to move columns



    So just try its last option ‼

  5. #5
    Registered User
    Join Date
    06-13-2012
    Location
    Jacksonville, fl
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: CSV Import causing Header row to move columns

    xlOverwriteCells worked! Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Copy columns based on header (Without header)
    By Michael_BU in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-15-2014, 08:07 AM
  2. Replies: 2
    Last Post: 10-13-2012, 03:30 AM
  3. [SOLVED] Import multiple .TXT/.TAB files only using one header row
    By Delta in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-04-2012, 01:58 PM
  4. Move Columns Based on Header
    By MSmithson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-30-2010, 08:22 PM
  5. Pasting Multiple Columns causing problems
    By sgs521 in forum Excel General
    Replies: 1
    Last Post: 09-25-2007, 06:05 PM
  6. [SOLVED] How do i import header and footer from diferent XLS file?
    By Beck in forum Excel - New Users/Basics
    Replies: 1
    Last Post: 06-26-2006, 03:25 PM
  7. [SOLVED] Move or copy sheet causing the creation of an htm file
    By drlogarithm in forum Excel General
    Replies: 0
    Last Post: 11-07-2005, 01:10 PM

Tags for this Thread

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