Closed Thread
Results 1 to 10 of 10

Allocation of columns to other sheet based on matching headers

  1. #1
    Registered User
    Join Date
    02-12-2016
    Location
    Zurich, Switzerland
    MS-Off Ver
    MS Office 2013
    Posts
    94

    Allocation of columns to other sheet based on matching headers

    In the attached Excel file i'm trying to figure out how to allocate columns of the sheet "InfoPath Import" to the correct columns in the sheet "Final Layout".

    The problem is, that when I import data from the InfoPath forms, there are not always the same number of column header which makes the allocation to sheet "Final Layout" harder. The header names are the same, but not their positions.

    Is there maybe a way to only always load/import certain columns at the same positions? If not, how could I accomplish the allocation with a macro?

    Many many thanks for your help and support!

    Best regards,
    Attached Files Attached Files
    Last edited by etaver87; 05-23-2016 at 08:07 AM.

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Allocation of columns to other sheet based on matching headers

    Although I can't help you enough with your question in VBA; you show no results so forummember maybe will not know what you want to achieve. That could be the reason you have no respond on the question (41 views).
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Forum Contributor IonutC's Avatar
    Join Date
    01-28-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    Office 2019
    Posts
    486

    Re: Allocation of columns to other sheet based on matching headers

    Hi,

    I had this situation before and i was not able to find the right answer. My solution however was to manualy add the columns to my destination.
    So if you know that in the source file col. A has to be inserted into col. G in the destination file you can do a macro that will copy all your columns based on a specified position.

    Please find below an example of a code:

    Please Login or Register  to view this content.
    you can create also a variable that will calculate your lastrow so you can do a Foor Loop function:

    the code can be
    Please Login or Register  to view this content.
    B in my example is a function in which you can assign a value. in the format "cells( B, 15) B repents the row and 15 the column.
    Also you will need to have no blank cells into your columns...

    Hope that it helps.
    Please consider:
    Be polite. Thank those who have helped you.
    Click the star icon in the lower left part of the contributor's post and add Reputation. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .
    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Posting code between tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

  4. #4
    Registered User
    Join Date
    02-12-2016
    Location
    Zurich, Switzerland
    MS-Off Ver
    MS Office 2013
    Posts
    94

    Re: Allocation of columns to other sheet based on matching headers

    Thanks a lot for this first step. the problem is, that it is not always the same column from sheet "InfoPath Import" that corresponds to a certain column in the "Final Layout". I think it would be best to match the headers from sheet "InfoPath Import" with the ones from "Final Layout" That way I would have the right data below each header in the sheet "Final Layout".

    I updated the template upload from my first post.

    So basically, Excel should check from the InfoPath Import sheets (in the final version it will be just one sheet where I import the data which then gets loaded into the "Final Layout" sheet) the headers and copy to the columns in "Final Layout" with the same header. The thing is that after the imports, the headers are not always in the same column, so therefore there is the need for matching headers.
    Last edited by etaver87; 05-23-2016 at 08:09 AM.

  5. #5
    Forum Contributor IonutC's Avatar
    Join Date
    01-28-2016
    Location
    Bucharest, Romania
    MS-Off Ver
    Office 2019
    Posts
    486

    Re: Allocation of columns to other sheet based on matching headers

    Hi,

    I can't help you further. I had an idea of having a dynamic area, but I don;t know how to write the code so you can find the specified column.

    Maybe we can see, if other reply to your question and to learn both of us the solution.

    Have a great day ahead,
    Ionut

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

    Re: Allocation of columns to other sheet based on matching headers


    Hi !

    If headers are exactly the same, no matter their position with an advanced filter …

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Allocation of columns to other sheet based on matching headers

    Hi, if you start working with non consistent column names then manual checking is the only option.
    I have reattached your file but added a worksheet named Layout-Sheet
    Column A o=contains the requested output layout and column B the corresponding column number; A=1, B=2 etc.

    In Column C I placed the top row of your input file.
    In Column D you could place the corresponding column number of the input file or you can place the column number of where you want it to be placed in the output sheet

    You would the need vba code to read each row and check win which column each value has to be placed.

    This is just a quick-and-dirty explanation but it's just to give you my idea and something to brood upon.

    If you have more source layouts then you would have to do the same for each and maybe it can work.

    See if you can work something out, I'd gladly help and stick time into it if you need more help.
    Attached Files Attached Files
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  8. #8
    Registered User
    Join Date
    02-12-2016
    Location
    Zurich, Switzerland
    MS-Off Ver
    MS Office 2013
    Posts
    94

    Re: Allocation of columns to other sheet based on matching headers

    Thanks so much for your time, really appreciated!

    Have you seen the newest template I uploaded in the first post? What if the headers are the same? Then it should be easier, no? That would be a solution too.

  9. #9
    Registered User
    Join Date
    02-12-2016
    Location
    Zurich, Switzerland
    MS-Off Ver
    MS Office 2013
    Posts
    94

    Re: Allocation of columns to other sheet based on matching headers

    I saw something similar in another workbook, where in "LeaveDates" we have the first row with date headers (not every date of the year) and the "AllDates" sheet has all dates of the year in the headers. The following macro then filled only those columns in "AllDates" that matched with the headers in "LeaveDates":

    Please Login or Register  to view this content.
    maybe that helps someone or you Keebellah find the solution?

  10. #10
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Allocation of columns to other sheet based on matching headers

    etaver87, duplicate posts are a rule violation. If you need to clarify your question, please do so in the existing thread instead of starting again in a new thread. This is confusing to the people who have been trying to help in the original thread. Rather than try to merge the threads and cause even more confusion I am going to close this one, referring members to your newer thread.

    This is a duplicate post and as such does not comply with Rule 5 of our forum rules. This thread will now be closed, you may continue in your other thread.

    Thread Closed.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Copying columns from one sheet and pasting to another based on headers
    By magnus12 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-08-2015, 10:43 PM
  2. Get value based on columns and row headers
    By KJL in forum Excel General
    Replies: 2
    Last Post: 05-06-2014, 01:36 PM
  3. Replies: 4
    Last Post: 02-08-2014, 02:31 PM
  4. Selecting Multiple columns based on headers and copying to seaperate sheet
    By jonto81 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-03-2013, 10:44 AM
  5. Budget allocation: Find out how much can be spent based on other columns
    By hojo79 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-05-2012, 06:31 PM
  6. Macro to Sum Columns based on Headers
    By Jluc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-24-2011, 02:36 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

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