+ Reply to Thread
Results 1 to 12 of 12

Export Columns to New Worksheet

  1. #1
    Registered User
    Join Date
    07-24-2008
    Location
    London
    Posts
    43

    Export Columns to New Worksheet

    I am using the following Macro to copy certain columns to a new Worksheet in a particular order which is working fine however I have two issues:

    1 - When the new worksheet is created the column widths are not being exported over so I have go to the new worksheet an manually adjust the width again.

    2 - I have a number of columns which will be move when additional columns are added i.e. from column AB to AC which means I have to change the code again.Is there a way to track these so I do not have to change the code again. In row 5 each of the columns has a unique heading.

    Please Login or Register  to view this content.
    Can anyone help?

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Export Columns to New Worksheet

    If the columns in question have a specific value at the top, a header, then you can spot the location of the column(s) at any given moment by searching for that specific value in the row the headers are found in, typically row1.

    Please Login or Register  to view this content.

    It's lengthy, but robust...
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Export Columns to New Worksheet

    This is robust, too, you need only expand the two arrays. The first array is the value you're searching for, the second array is the target address for when the value is found.
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-24-2008
    Location
    London
    Posts
    43

    Re: Export Columns to New Worksheet

    Thanks. I actually prefer the second piece of code you provided with the array. The only issue is my headings are on Row 5 so that's where I want the Macro to do the search for the heading and then copy the entire column including Row 1,2,3,4 above the headings i.e.all the data in the column after it finds the heading in Row 5.

  5. #5
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Export Columns to New Worksheet

    So you change the .Row(1) to .Row(5), yes?

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  6. #6
    Registered User
    Join Date
    07-24-2008
    Location
    London
    Posts
    43

    Re: Export Columns to New Worksheet

    I tried this before and now tried it again after getting confirmation from you with the same result.

    When the headings are on Row1 the export works fine. When the headings are moved to Row5 and the code is changed to Row(5) the export sheet is created but it is BLANK.

    Any suggestions?

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Export Columns to New Worksheet

    First suggestion is always post a sample file where we can simply see the same things at the same time.
    (Go Advanced > Paperclip).

    Maybe this:
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    07-24-2008
    Location
    London
    Posts
    43

    Re: Export Columns to New Worksheet

    This now works fine which is brilliant. The last amendment - I have a large block of columns i.e. from AZ to FC which will never change which I will want in columns FA:JD in the export . I was wondering if I could add these somewhere as AZ:FC so I do not have to enter all the names again. If this cannot be done I will have to add these in manually (108 names). This was quite simple in the code I posted.

    If needed I could post a sample.

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Export Columns to New Worksheet

    Maybe add this:
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    07-24-2008
    Location
    London
    Posts
    43

    Re: Export Columns to New Worksheet

    Awesome that works perfect!!! Before I mark this as complete is there a way of making certain columns in the export hidden. I am sure there is something quite simple.

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Export Columns to New Worksheet

    Columns in which sheet?
    Which columns?

  12. #12
    Registered User
    Join Date
    07-24-2008
    Location
    London
    Posts
    43

    Re: Export Columns to New Worksheet

    There are a few columns i.e. 'address', 'city' in the original spreadsheet which I want exporting to a new sheet however I want them hidden in the new sheet.

    The plan is to export say Columns A:FC however from within these columns I want certain ones columns hidden when they appear in the export.

    Hope that makes sense.

+ 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