+ Reply to Thread
Results 1 to 6 of 6

Match, Copy and Paste Column Headers - varying number of columns

  1. #1
    Registered User
    Join Date
    11-27-2012
    Location
    bristol
    MS-Off Ver
    Excel 2010
    Posts
    16

    Match, Copy and Paste Column Headers - varying number of columns

    Hi All.

    As with many people on this forum, I have recently delved into VBA and am pretty much learning on the fly. This site, and the others like then have been of immense use. However I am embarking on a project that is not something ive been able to search and find. Most topics are covered with a simple search, this one is a bit beyond me, perhaps I’m using the wrong terminology.

    A quick overview of the data we have:

    We regularly receive details of monthly payments made and owed to us. There is one worksheet for Payments Paid, and one for Payments Due, in the same workbook. We then add a worksheet, Payment History. This is all against a customer ID.

    Hopefully the attachment will show what I mean more clearly.

    Payment History is a summary sheet and we construct this by putting ‘Paid month 1’ in a column, and then Due month 1 in the column next to it….then onwards with Paid2/Due2, Paid3/Due3 etc etc. As shown in the workbook.

    What I need to do:

    I have a macro stored in there that works brilliantly, although it’s not fully complete its just an example of what it should execute. Effectively, it looks for a column name in Payment Paid or Payment Due, matches it with the column name in Payment History and copies and pastes that data into the corresponding column in the summary sheet, Payment History.

    In this example we have 12 months of history. I could write the code to copy and paste each column for that 12 months into the summary sheet, but the kicker is, the number of months can vary significantly.

    So to avoid handling errors, I would love to know how to loop the code so that it stops copy and pasting at the last column it comes to and finds a match. This sounds pretty dynamic and I’m not even sure this is possible, it’s certainly was above my head. For starters how do I tell the macro to match headers that effectively have to be passed to the macro in the first place??


    I really hope I have made sense. Please let me know if I need to elaborate on anything and I will try as best I can to clarify. In the meantime, thanks for reading and thanks in advance for any help.


    Itcher
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    11-27-2012
    Location
    bristol
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Match, Copy and Paste Column Headers - varying number of columns

    apologies, i noticed an error in my workbook, please use this one.

    thanks again!

    itcher
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    11-27-2012
    Location
    bristol
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Match, Copy and Paste Column Headers - varying number of columns

    can the code reference a starting cell, then loop using a usedrange or something?? really stuck here...

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Match, Copy and Paste Column Headers - varying number of columns

    itcher,
    Try the attached.
    You have payment due only on your code, but I have also done another code- the same for payment paid sheet. In case you do not want that, I have separated the codes, but linked them by calling the payment paid from payment due, so if you want payment due only, we can easily remove the link(Call code). The code clears existing data and repopulate with fresh data.
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    11-27-2012
    Location
    bristol
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Match, Copy and Paste Column Headers - varying number of columns

    WOW! simply outstanding work. i really dont know how to thank you. Not just a push in the right direction it does EXACTLY what was needed.

    Bless your very kind heart.

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Match, Copy and Paste Column Headers - varying number of columns

    Itcher,
    You are welcome!

+ 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