+ Reply to Thread
Results 1 to 8 of 8

Import user selected columns from a text file

  1. #1
    Registered User
    Join Date
    09-20-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    13

    Import user selected columns from a text file

    Hi,

    I'm trying to write a macro that imports a tab delimited text file. The issue I'm having is that the files tend to be pretty big, so I want it to only import the reference columns (from 1 to 6) and channel columns (from 1 to 16) selected by the user.

    I've managed to write an inelegant if statement that works for the channel select option but adding in the reference option would give almost 100 different scenarios, so I figured there has to be a better way to do this

    I've attached a text file showing roughly how the data is presented in the text file (there are a lot of useless columns but this is the way it's given to me for now) and a file with the macro that I've been using for one option.

    Hope someone can help.

    Cheers.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Import user selected columns from a text file

    Hi

    Do all the columns that have DISABLED as the heading, really have that as the heading, or do they have something meaningful that you have disguised for the example purposes?

    rylo

  3. #3
    Registered User
    Join Date
    09-20-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Import user selected columns from a text file

    Hi rylo,

    No, DISABLED is not the actually heading. Most of the columns with that are actually rarely or never used, but there are a few that my boss would prefer I not make public. So to make things less confusing I just disguised all the headers that aren't needed for this issue.

    aarho

  4. #4
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Import user selected columns from a text file

    Hmmm

    I was thinking about using adodb to bring in the required columns, but unfortunately the first row isn't a heading row, and as there are spaces in the heading names (even if it was the first row), then it wouldn't work.

    Back to the drawing board....

    rylo

  5. #5
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Import user selected columns from a text file

    Hi

    OK, this is a bit clunky but here goes.

    1) Home!B5 - create a data validation dropdown list referencing range U2:U16. This will enable you to directly select the channel heading.
    2) Home!D5 - create a data validation dropdown list referencing range T2:T9

    Make selections in both of those cells. Then try

    Please Login or Register  to view this content.
    You will have to update it for the extra columns that you want as I don't have access to the real headings, but hopefully you will get what I'm trying to do. It does open the file completely in Excel, but then shuts it down again. If you turn off the display, then it really shouldn't be a problem.

    Good luck

    rylo

  6. #6
    Registered User
    Join Date
    09-20-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Import user selected columns from a text file

    rylo! You're awesome!
    Once again you solved my problem and in a way that should help improve some other stuff I've done and make them much more efficient!

    I was hoping you could walk me through this one a bit. I'm still a little green when it comes to this stuff (I'm sure that's pretty obvious), so I think maybe there's a step I'm not seeing or understanding.

    As I see it, this is how the macro you wrote works:


    1- Prompt to select file
    2- Insert a new sheet with name the value of cell A1
    3- Set table headers
    4- Open the selected .txt file
    5- Get data table dimensions (lastrow, lastcol)?
    6- Apply a filter and copy to A1:F1 in the new sheet
    7- Close the selected file

    I think my confusion is coming at the filter stage. I'm just not seeing where or how it's telling it to go to the ref and ch columns selected. It clearly is because it's working great, but I'm not seeing it.

    Thanks

    aarho

  7. #7
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: Import user selected columns from a text file

    aarho

    You have got the steps spot on.

    With the filter, it puts in the headings into the output sheet, inlcuding the headings selected in the main file. As you have the headings that are in the raw data file, that is used by the filter when determining what to output from the filter process. I know that there are a couple of headings missing, but as I don't have the real headings in the raw file, I couldn't include them in the output. I think there are 2 (or 3) missing fields, so if you determine what those headings are you can include them in the fixed component, then put the user selected ones further over. You will have to adjust the output placement of the user selected ones.

    If you open the raw text file in excel, you will see that it puts the headings into row 3.

    If that doesn't make sense, then build yourself a little test file with some dummy headings and data, and see just how the filter works. That may make things clearer.

    rylo

  8. #8
    Registered User
    Join Date
    09-20-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    13

    Re: Import user selected columns from a text file

    I think I get it now. Thanks a lot for all your help!

    aarho

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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