+ Reply to Thread
Results 1 to 13 of 13

Search by columns headers and paste all matching columns to another sheet

  1. #1
    Registered User
    Join Date
    01-26-2020
    Location
    Warsaw, Poland
    MS-Off Ver
    365
    Posts
    28

    Search by columns headers and paste all matching columns to another sheet

    Hi, would you help me with a macro (because I think there is no other option) which will allow to:

    1. Find a match picked from a dropdown list (sheet2) among column headers in sheet1
    2. Copy all columns which will match
    3. Paste those in sheet2 all next to each other

    For Example, if in sheet2 from dropdown list was chosen "Wera", then macro looks into each column headers in sheet1 to find match, then it will copy all columns (header and data) and paste in in sheet2.
    Please take a look on the file that I've prepared. In real file there is much more columns and rows.

    Thanks,M.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Search by columns headers and paste all matching columns to another sheet

    To Sheet2 code module
    Please Login or Register  to view this content.

  3. #3
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,525

    Re: Search by columns headers and paste all matching columns to another sheet

    If the found columns (to be copied) will be less than about 60, then the macro below should be fine.
    Place the routines in the Arkusz2(Sheet2) module.
    Please Login or Register  to view this content.
    Artik

  4. #4
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,957

    Re: Search by columns headers and paste all matching columns to another sheet

    Another Option...As per column limitation...
    Please Login or Register  to view this content.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Search by columns headers and paste all matching columns to another sheet

    Quote Originally Posted by Artik View Post
    If the found columns (to be copied) will be less than about 60, then the macro below should be fine.
    Please Login or Register  to view this content.
    Artik
    Quote Originally Posted by sintek View Post
    Another Option...As per column limitation...
    Why keep posting such incomplete codes where there is a work around.
    I didn't use this, because it still need to loop.
    Please Login or Register  to view this content.

  6. #6
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,957

    Re: Search by columns headers and paste all matching columns to another sheet

    @ jindon...

    But why oh why...In previous thread here when you referenced Excel limitations, I assumed the functionality of this fell within the Column Sort Limitation...Although not specifically pointing to non contiguous column grouping...If the column count is within the limitations...Does it not render same result?

    I have run all the codes with Column count < limit ...and the same results are rendered...I understand that one should ideally make provision for possible limitations but if the sample data falls within theses limitations, surely, the snippet could be used?

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Search by columns headers and paste all matching columns to another sheet

    That's nothing to do with this "LIMITATION".

    Sub-sting of Range object needs to be less than 256 characters.

  8. #8
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,957

    Re: Search by columns headers and paste all matching columns to another sheet

    jindon...Please forgive my ignorance...When I joined this forum, I knew nothing about excel...Only by following posts and guidance of members such as yourself & others have I managed to get a better understanding of VBA...I have had no education or followed any tutorials...I only learned what I needed at the time to get the job done...So to say...And yes, by now I should have done further investigation into the "nitty gritty" of Excel but this is a side line hobby and not my career...happy to learn as I go along...Thank you once again for your valuable lesson...

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Search by columns headers and paste all matching columns to another sheet

    What I'm trying to say is that are you happy to receive the code that has a knowing problem when you ask question?

  10. #10
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,957

    Re: Search by columns headers and paste all matching columns to another sheet

    No I suppose not...Should supply code that will accommodate all possible eventualities...Just in case...And not supply code that just gives the correct result for supplied dataset...

  11. #11
    Registered User
    Join Date
    01-26-2020
    Location
    Warsaw, Poland
    MS-Off Ver
    365
    Posts
    28

    Re: Search by columns headers and paste all matching columns to another sheet

    Hi, I have tried this on the mockup file and it was working just fine. But right now I replaced data with real ones and it shows me me error: run-time error "13": type mismatch. And it's pointing to:
    x = Join(Filter(.Parent.Evaluate("if(" & .Rows(1).Address & "='" & _
    Me.Name & "'!d2,address(1,column(" & .Address & "),4)&"":""&address(" & _
    LR & ",column(" & .Address & "),4))"), False, 0), ",")
    Last edited by maamon; 08-13-2021 at 10:01 AM.

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Search by columns headers and paste all matching columns to another sheet

    Your picture files are invalid so can not open.

    1) Right click on Sheet2 tab and [View Code]
    2) Paste the code onto the right pane and close vbe window.

    It will execute when you change D2.
    Attached Files Attached Files
    Last edited by jindon; 08-13-2021 at 09:31 AM. Reason: File attached

  13. #13
    Registered User
    Join Date
    01-26-2020
    Location
    Warsaw, Poland
    MS-Off Ver
    365
    Posts
    28

    Re: Search by columns headers and paste all matching columns to another sheet

    Hi, All works now. In the real file it were email addresses in the dropdown list to lookup and once I have removed "@company.com" it started working fine. Once again many 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. Returning the headers of all columns with a matching value
    By smohyee in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-08-2021, 06:33 PM
  2. Allocation of columns to other sheet based on matching headers
    By etaver87 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-24-2016, 09:44 AM
  3. Allocation of columns to other sheet based on matching headers
    By etaver87 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-24-2016, 09:41 AM
  4. macro to add columns after existing columns and copy/paste headers and formulas
    By rhybeka in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-21-2013, 02:35 PM
  5. [SOLVED] Search Multiple columns for string, display matching results on different sheet.
    By RichTea88 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-06-2013, 06:53 AM
  6. [SOLVED] Search Copy and Paste two columns in different sheet
    By mahtabshaikh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-01-2012, 01:26 PM
  7. Auto filter multiple columns matching with searched headers
    By gotovamsee in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-08-2011, 03:20 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