+ Reply to Thread
Results 1 to 4 of 4

Macro to import data from specific columns form csv and rearrange

  1. #1
    Registered User
    Join Date
    05-21-2013
    Location
    Rotherham
    MS-Off Ver
    Excel 2010
    Posts
    2

    Macro to import data from specific columns form csv and rearrange

    Hi, I am a complete novice at Macros and I need to make one to import data from a delimited csv, but I only need a few columns of data and I need to rearrange the order of the gathered data in to the currently selected cell/row of my spreadsheet.

    The csv would have the same columns each time, but the number of rows would be different, I have attempted this so far by doing this, but this is only collecting from one column as I don't know how to rearrange the data, can anyone help me?

    Tony

    Sub Macro1()
    '
    ' Macro1 Macro
    '

    '
    With ActiveSheet.QueryTables.Add(Connection:= _
    "TEXT;example.csv", Destination:=ActiveCell)
    .Name = "examplecsv_2"
    .FieldNames = True
    .RowNumbers = False
    .FillAdjacentFormulas = False
    .PreserveFormatting = True
    .RefreshOnFileOpen = False
    .RefreshStyle = xlInsertDeleteCells
    .SavePassword = False
    .SaveData = True
    .AdjustColumnWidth = True
    .RefreshPeriod = 0
    .TextFilePromptOnRefresh = False
    .TextFilePlatform = 850
    .TextFileStartRow = 2
    .TextFileParseType = xlDelimited
    .TextFileTextQualifier = xlTextQualifierDoubleQuote
    .TextFileConsecutiveDelimiter = False
    .TextFileTabDelimiter = True
    .TextFileSemicolonDelimiter = False
    .TextFileCommaDelimiter = True
    .TextFileSpaceDelimiter = False
    .TextFileColumnDataTypes = Array(9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, _
    9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9)
    .TextFileTrailingMinusNumbers = True
    .Refresh BackgroundQuery:=False
    End With

    End Sub

  2. #2
    Registered User
    Join Date
    05-15-2013
    Location
    Wisconsin, USA
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Macro to import data from specific columns form csv and rearrange

    where do you want to rearrange it to?

    Do you have a problem getting the data into the sheet in the first place?

  3. #3
    Registered User
    Join Date
    05-21-2013
    Location
    Rotherham
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Macro to import data from specific columns form csv and rearrange

    Hi, thank you for your reply.

    The csv has 40 columns and say I need to collect data from column 10, 12, 18, 25, 26 and 29, but then place that data in a row on my spreadsheet in the following column order: 25, 12, 29, 18, 10, 26, so that data from column 25 of the csv would be placed in column 1 of my spreadsheet and so on.

    How would I adjust my Macro so that it would do this?

    Tony

  4. #4
    Registered User
    Join Date
    05-15-2013
    Location
    Wisconsin, USA
    MS-Off Ver
    Excel 2010
    Posts
    42

    Re: Macro to import data from specific columns form csv and rearrange

    You could record macro and import each column one by one or you can do macro to cut and paste the rows after importing. The first might take longer but would be better approach.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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