+ Reply to Thread
Results 1 to 42 of 42

VBA Macros to copy dynamic columns data to standard columns.

  1. #1
    Valued Forum Contributor
    Join Date
    01-11-2012
    Location
    Riyadh, K.S.A.
    MS-Off Ver
    Windows 11 with Excel 2013 & 2016
    Posts
    900

    VBA Macros to copy dynamic columns data to standard columns.

    Hello Again,

    I am looking for VBA Macros where I can list header values automatically as caption of options button based on column counts for multiple sheets and based on selection copy the entire column data to sheet1.

    Details:
    Every health provider is submitting the data in dynamic format example 1 provider mentioned member name in column B and another submit their same information in column F.

    So, I requesting for a macro where both column header listed on user form so that a user can select from which column the data need to copy to which data.

    Example:
    Sheet1 column data is fixed. If provider submit their member ID in column G then from user form if I select member ID, the data should copy from column G to sheet1 column C.

    For example, if the provider submits their Quantity in column H in data sheet then if I select Quantity it will copy data from column H from data sheet to column I in sheet1.
    Attached Files Attached Files

  2. #2
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Hello hecgroups,

    I am not sure I understood your requirement 100% but I "think" what I did is what you need. I have attached a file with a UserForm where the user will be prompt to select the sheet he/she wishes to copy from then do the matching column along with the main sheet. Just make sure to change the main sheet name in the top code of the UserForm. Let me know if this works for you or you need further assistence

    Please Login or Register  to view this content.
    Attached Files Attached Files
    If I was able to help, you can thank me by clicking the * Add Reputation under my user name

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Hi downloaded your file and and nankw83's file too
    ---
    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

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    I have one question.
    The lay-out for the new posting has nothing to do with the previous project I developed for you, correct?
    Will the data of the files that you receive be appended to existing data or do you just want to import the new data but ordening it in the columns as you have now in Sheet5?

  5. #5
    Valued Forum Contributor
    Join Date
    01-11-2012
    Location
    Riyadh, K.S.A.
    MS-Off Ver
    Windows 11 with Excel 2013 & 2016
    Posts
    900

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Yes that project is different than this one.

    Yes I need to copy the data from other sheet to the sheet5 because the data submitted by the health provider will be in dynamic formats.
    I think the response it the +ve which nankw83 have posted. I am testing that file also but I need have different approach as it will be taking time to map column to column.

  6. #6
    Forum Expert nankw83's Avatar
    Join Date
    08-31-2015
    Location
    Kuwait
    MS-Off Ver
    365
    Posts
    1,712

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Hi hecgroups ,

    My first approach was trying to auto match the columns based on the text (partial match) but there was a lot of differences. For example, in your sheet5 you have "Dis" and "Dis Amt" where if I try to match & I get "Amount Claimed Before Discounts". While the approach provided in post #2 might work, it is very time consuming & is almost manual. If you have tips as a solid logic of how to match the columns let us know & perhaps we could adapt that logic

  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: VBA Macros to copy dynamic columns data to standard columns.

    Am working on my idea

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Update later

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    I have a project I developed for a client of mine that has exactly the same issues, data is offered in varying columns and I found a great solution for it.
    I'm making some changes to simplify it so it works for your case, and yes, the manual actions can be 0 once the layouts are configured. It works straightforward and can if all is set correctly work unattended as far as it goed to column allocation.
    What you did not answer is if the data you want to import is appended to an existing file with the sheet5 layout or that you want to create a new workbook for every import.

  10. #10
    Valued Forum Contributor
    Join Date
    01-11-2012
    Location
    Riyadh, K.S.A.
    MS-Off Ver
    Windows 11 with Excel 2013 & 2016
    Posts
    900

    Re: VBA Macros to copy dynamic columns data to standard columns.

    I don't know actually but for your convenient if it required changes on health provider submitting data then make it. What all I need here is copy the unformatted data into standard format which is in sheet5. The other sheets I don't mind as I have the original data as a backup.

    So, if it is easy to make changes and work for me then go a head.

    However the minor changes will done if required after the revision of you provider me the solution.

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Will do my best, but give me a little time

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    This is a test file, it does not import anything it just helps you to allocate / map the data from the provider to your Sheet5 fields.
    This form is in principle the same I have for the project I mentioned, it's a one-time action once you have mapped the columns you want.
    I saves the mappings in a table and uses this when you actually want to import the data.
    This part, the importing is not implemented.
    What it does when you open the form it lists the table with in the worksheet Collumn_Allocation, the first three columns are :
    A: The column header YOU have (Sheet 5) which for some reason has no spaces but that's no problem
    B: will hold the mapped column number of the selected file to import
    C: just holds the numberformat you have given the your corresponding fields, it reads if from the first data row in Sheet5

    I tested both the Format sheets you have here and you see that there are two extra columns with a fieldname in it.
    If you select the worksheet in the Allocation form it will read and check and show the columns numbers and the allocated fields
    It's far from complete but it does work and recognize the headers as you can see from the list in Format1

    Like I said it's far from complete but the manual work is only once and only if you receive other files.
    Attached Files Attached Files

  13. #13
    Valued Forum Contributor
    Join Date
    01-11-2012
    Location
    Riyadh, K.S.A.
    MS-Off Ver
    Windows 11 with Excel 2013 & 2016
    Posts
    900

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Dear Keeb,

    I really appreciate your efforts.

    Actually it is a good idea to store the heading but can it be stored for each provider so that if the same provider submitted the data then it will look for the existing mapping records then as for the user to manually map.

    So that if the same provider submit their data in future then automatically it will match the heading.

    Can it be possible.

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Well, that is exactly what I have been explaining. I guess that did not come across as intended.
    Like I said "Once the mappings are set you won't have to worry about them unless a new provider comes with an entirely different lay-out.
    What I do need YOU to tell me is which cells in YOUR file will always need to be mapped, I can imagine that you want a minimum number of columns populated to be able to work with it.
    Hope you understand my question.

  15. #15
    Valued Forum Contributor
    Join Date
    01-11-2012
    Location
    Riyadh, K.S.A.
    MS-Off Ver
    Windows 11 with Excel 2013 & 2016
    Posts
    900

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Currently we are under process of arranging the mandatory fields. But form now on we are using entire fields are open (Non-Mandatory) so that what every information we can get through the data will be enough.

    But i prefer to get all the fields will be better. as the total field are 58. However will get you the list of mandatory fields.

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Your sample file only has about 20 I think

  17. #17
    Valued Forum Contributor
    Join Date
    01-11-2012
    Location
    Riyadh, K.S.A.
    MS-Off Ver
    Windows 11 with Excel 2013 & 2016
    Posts
    900

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Hai Keeb,

    Yes. The beauty of your file is, it will automatically read the headers. If in future the column are increased the file read them automatically.

    Please find the attached original headers.
    Attached Files Attached Files
    Last edited by hecgroups; 06-05-2020 at 05:27 AM.

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Correction, you now have 30 fields.
    This template test is just to show how you can map the fields
    This is what I would then implement to use when actually filling in the data.

    The idea is that the mapping is checked and if nothing missing the just do the import else warn and let you still add / correct the mappings and THEN read the source file (again)

    Hope this makes sense to you
    Attached Files Attached Files

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    You did not set the cell format in the first row UNDER the header for the new headers, could you do so< this will acccelarate the correct formatting

  20. #20
    Valued Forum Contributor
    Join Date
    01-11-2012
    Location
    Riyadh, K.S.A.
    MS-Off Ver
    Windows 11 with Excel 2013 & 2016
    Posts
    900

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Means you want the same data filled under the header to know the format for each field correct.

    Let me prepare some and upload the same again with new headers.

  21. #21
    Valued Forum Contributor
    Join Date
    01-11-2012
    Location
    Riyadh, K.S.A.
    MS-Off Ver
    Windows 11 with Excel 2013 & 2016
    Posts
    900

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Here is the sample with format for new headers. please check and if you have any question or required more details tell me

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    I’m away fro my system but will look at it this evening
    I’m sure it will be fine

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Okay, I don't think you've formatted ROW2 correctly if I look at the header title but what about columns AG through BF ?

  24. #24
    Valued Forum Contributor
    Join Date
    01-11-2012
    Location
    Riyadh, K.S.A.
    MS-Off Ver
    Windows 11 with Excel 2013 & 2016
    Posts
    900

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Hai Keeb,

    I am sorry but I cannot get that data but still I am trying my best to get it as uptill now no health provider submit their data for these columns. But I am referring to guidelines for these column that need any specific format like 2 digits numbers, date format, description, etc...

    I will update to you once I obtained these information. But think it can be fixed later also or you need it now to make the file.

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    No problem, I’ve enough to figure out what it can be and yes, it can be changed afterwards the code is dynamic

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Okay, this works for now, you will have to test and see if you can map the columns, this is a one-time action for each of the three formats you have included
    Like I mentioned before I'm going to integrate this in a Template file and then all you will need to do is select the provider's file, open it and select the worksheet where the data is, press the button to populate the listbox on the right with the mapped columns and then run the copy action which is the code that nankw83 wrote.
    You can see what it does.
    Attached Files Attached Files

  27. #27
    Valued Forum Contributor
    Join Date
    01-11-2012
    Location
    Riyadh, K.S.A.
    MS-Off Ver
    Windows 11 with Excel 2013 & 2016
    Posts
    900

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Hai Keeb,

    I have done what you said it is display as error as mentioned below.

    Please Login or Register  to view this content.
    Also some of the header return in column I for example: ICD Code

    Kindly see the attachment.

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Will have to see what you’ve done, works here

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Found the reason why it failed, I used part of nankw83's code but forgot to take into account that I switched the two listboxes.
    Should work as intended now
    Attached Files Attached Files

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Hi have you had a chance to look at it?

  31. #31
    Valued Forum Contributor
    Join Date
    01-11-2012
    Location
    Riyadh, K.S.A.
    MS-Off Ver
    Windows 11 with Excel 2013 & 2016
    Posts
    900

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Hai keeb,

    It works like a magic. Thanks once again.
    Also I will check thoroughly with different formats and get back to you with detail feedback.
    Thank once again.

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Well, then I can give you the next one

    When the allocation form is opened you first need to click the option button (red arrow points to the OptionButton) to open a file browser to select a folder and the a file from the list that will be generated.
    The rest works the same as the previous one only this one uses a file YOU select.
    The first thing is assign all the columns but that's a one time action.

    The only thing missing here is a macro that saves the template sheet as a separate excel file for your use
    Attached Images Attached Images
    Attached Files Attached Files

  33. #33
    Valued Forum Contributor
    Join Date
    01-11-2012
    Location
    Riyadh, K.S.A.
    MS-Off Ver
    Windows 11 with Excel 2013 & 2016
    Posts
    900

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Hai Keeb,

    Thank you very much for your valuable help. I have some questions to ask.

    1. In future can the header will be increased or decrease based on system requirement.
    2. Can I change the Column_Allocation cell values.
    3. Why the header move to row 3
    4. I just want to ask about this option but you have already implemented.
    However my question is the header must be in row 1 for Data Source file as you know that the format
    is different from workbook to workbook.
    Example: I found a file which is having merge cell with 2 columns and header is having image (Logo), etc..


    Some additional request.
    1. Can the headers list in alphabetical order foe easy to select.
    2. Column_Allocation worksheet can be hide (Means work at background)

    Thank you for your help and support.

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Let me read what you've said and I'll try and answer sometime later.
    For what concerns point 3, the header row is just to show that it doesn't matter where the header starts, it works.
    You want row 1, just delete the two entire rows above the template sheet and you're back to row 1

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    I wrote placed my answers and comments in the attached word file
    Attached Files Attached Files

  36. #36
    Valued Forum Contributor
    Join Date
    01-11-2012
    Location
    Riyadh, K.S.A.
    MS-Off Ver
    Windows 11 with Excel 2013 & 2016
    Posts
    900

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Hai Keeb,

    Thanks for your help. I got the my answers.

    1. I will delete the logos (Images) and blank rows above the header before using the file.
    2. I will manually arrange the merge cells and other improper data which I received form provider.
    3. Happy to know that I can change the Column_Allocation which is same as header in my template to use this file in other work assignments which is much similar to this project.

    The only thing is left that sorting only list box items in alphabetical order to fetch the information easily.

    Thanks you very much for your valuable help which make my tough work easy on daily basis.

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Hi, maybe I was not clear enough, you DO NOT have to clear empty rows above the header rows, all data ABOVE the header rows will be ignored, so if your provider sends a file with some data above the header row the macro code will ignore that.
    The header row will be the first row that is not blank, but I could add a check to see if there are more than 4 columns filled then it will considered a header

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    I this this will help with the sorting
    Attached Files Attached Files

  39. #39
    Valued Forum Contributor
    Join Date
    01-11-2012
    Location
    Riyadh, K.S.A.
    MS-Off Ver
    Windows 11 with Excel 2013 & 2016
    Posts
    900

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Hai Keeb,

    Thanks a lot. I hope we have finalized the file but let me go through the entire options and possibilities before close this topic.

    Thank you once again for you valuable help.

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Well, I don’t know if it’s finalized, but it works
    There will always be options to be desired and more fine tuning but this is works
    Hope you enjoy it, it was above challenge and maybe I’ll put some work into it to make it useable as add-in
    Who knows, others might profit from your questions and the result

  41. #41
    Valued Forum Contributor
    Join Date
    01-11-2012
    Location
    Riyadh, K.S.A.
    MS-Off Ver
    Windows 11 with Excel 2013 & 2016
    Posts
    900

    Re: VBA Macros to copy dynamic columns data to standard columns.

    Hai Keeb,

    It works on my original data also.
    If in future if i required your assistance in this file can i contact you please.
    Currently i will mark this topic as solved.

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

    Re: VBA Macros to copy dynamic columns data to standard columns.

    No problem. Hope it also helps to stimulate your own programming skills
    Happy coding,

+ 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. Replies: 1
    Last Post: 05-21-2020, 11:49 PM
  2. Replies: 2
    Last Post: 05-21-2020, 03:27 AM
  3. Add data in multiple columns (dynamic # of columns)
    By neotaruntius in forum Excel General
    Replies: 7
    Last Post: 12-10-2019, 01:55 PM
  4. Replies: 0
    Last Post: 05-22-2014, 08:10 AM
  5. Replies: 2
    Last Post: 10-03-2009, 05:47 PM
  6. Converting columns of non-standard formatted data into a table (rows)
    By Peter33 in forum Access Tables & Databases
    Replies: 2
    Last Post: 10-02-2009, 04:36 PM
  7. Help reformatting block data into standard columns
    By dylanemcgregor in forum Excel General
    Replies: 8
    Last Post: 06-03-2009, 02:03 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