+ Reply to Thread
Results 1 to 92 of 92

Copy info from excel file to a template

  1. #1
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Copy info from excel file to a template

    Hello

    I need to macro in a template that will copy information from an excel file that is emailed to me daily (see sample data) to a template (see sample template). Any help would be greatly appreciated.

    Thx.

    Sorry not sure how to upload a second attachment (my template) so I included it as a seperate tab in file I attached.
    Last edited by Longbow 44; 03-29-2023 at 08:42 PM.

  2. #2
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Here is a process for you. Open the attached workbook and run the following code. The module will ask you to locate that days data file. The code will then use the template information to create and save a new file with the embedded data. Let us know how it works.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Thank you for your expertise in this area. I made an error in my sample data and I forgot there will be a column G, so an adjustment needs to be made to the code. I added it and re-attached the file and posted the example. Is it possible to add a condition so it will not copy any rows that have been colour formatted? I only want data in cells that have a white background. I added a couple more columns to my template as well so please extend the (border format) when the macro runs.

    Thx

  4. #4
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Again thanks I was able to change the code you wrote myself to make the changes I needed. The only thing remaining is to not copy any of the cells with formatted colour. Would it be a condition say rgb is (0) for white?

  5. #5
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    To remove copying over the formatting, change

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    You can also include two additional columns in the formatting by changing the H to J in the range code.

    I updated all of this below:
    Please Login or Register  to view this content.
    and Welcome to the forum. Since we are volunteers here, if you find my response helpful, you can show some appreciation by clicking on the bottom left star icon « ★ Add Reputation ».
    Last edited by maniacb; 03-16-2023 at 08:18 AM.

  6. #6
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    I made the code change but it still copies all of the data from source file. I do not want it to copy from rows (9/14/18/20/21/24/38). I attached the sample file.

    Thx
    Last edited by Longbow 44; 03-16-2023 at 08:31 PM.

  7. #7
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Try this update:

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Here is the sample with the and "x" in column Q to denote I do not want that row copied. This is the best option instead of looking for cells with no colour formatting.
    Last edited by Longbow 44; 03-16-2023 at 11:46 PM.

  9. #9
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    if you want to instead use the a value such as x in column Q instead of coloring the rows, the code would look like this.

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Big thanks

  11. #11
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    I would like help changing the code you wrote for additional requirements (see attached template) for explanation.

    Thx
    Last edited by Longbow 44; 03-18-2023 at 01:28 AM.

  12. #12
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Here is the updated code and template. I had to rewrite the formulas to include a dynamic detection of the last column to copy over appropriately. They are still the same formulas.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  13. #13
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Excellent! But I need a couple more changes to the code see attached file.
    Last edited by Longbow 44; 03-18-2023 at 01:10 PM.

  14. #14
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Possible issue: In the sample data, an x is only listed in some items in column 17, "Q". There are no x values in column 16, "P". Are you going to add the value x into column 16 going further? Or did you mean to check column 17 for the x value? But if we do that, after your last request, those lines with x in 17 will never use the new formatting if they are excluded from copying over. I included both lines of code so that you can remove either if you wish. Or let me know and I'll make the update.

    Please Login or Register  to view this content.

  15. #15
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    This update incorporates adding the conditional formatting to column K.

    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    There will never be an "x" in both 16/17 I was able to adjust the code. Thx
    I have a couple other items could you please look at the attached file.
    Last edited by Longbow 44; 03-18-2023 at 01:09 PM.

  17. #17
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Here is the update with the new code and template. The formulas have also been updated to only count to row 148.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  18. #18
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    One more change required and its done see attached for description.

    Thank you
    Last edited by Longbow 44; 03-19-2023 at 12:23 AM.

  19. #19
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    To convert
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    to a dynamic range use
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  20. #20
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Many thanks

  21. #21
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Your welcome. Have a nice day

  22. #22
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Is it possible to update the code to hide/remove the blank cells after the macro ruins? This will bring the table in b150:M170 up to the output table produced when the macro has run.

  23. #23
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Sure, I just added one line highlighted in red. Here is the full submodule:

    Please Login or Register  to view this content.

  24. #24
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    thank you once again

  25. #25
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Also when the macro runs could you have it turn sheet protection on please. Thx

  26. #26
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    I slightly rearranged and added the line to protect the sheet below.

    Please Login or Register  to view this content.
    If you want to add a password to protect the sheet use this line instead of the .protect line:

    Please Login or Register  to view this content.

  27. #27
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    When the macro runs I would like the table it produces to be not locked. My guess is some type of range needs to be written into the code. I noticed that when the macro runs the security settings for all the other cells copy to the new worksheet, so no other code is needed.

  28. #28
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Also when the macro runs and creates an array with the data and you enter a value in ((K)>0), it turns the cell red like it should. Then you can put a (Y) in L and change it to green, but when you delete the (y) it stays red, until you click the cell in K. Just curious why that is, shouldn't it change back from green to red automatically when Y is removed.

    Set c4 = rng.FormatConditions.Add(Type:=xlExpression, Formula1:="=ISBLANK(K2)")
    c4.Interior.Color = 16777215
    Set c1 = rng.FormatConditions.Add(Type:=xlExpression, Formula1:="=AND(K2>0,L2=""y"")")
    c1.Interior.Color = 11854022
    Set c2 = rng.FormatConditions.Add(Type:=xlExpression, Formula1:="=K2=0")
    c2.Interior.Color = 11854022
    Set c3 = rng.FormatConditions.Add(Type:=xlExpression, Formula1:="=AND(ISBLANK(L2),K2>0)")
    c3.Interior.Color = 10066431

  29. #29
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    To lock the table cells add the red code line where indicated below.

    Please Login or Register  to view this content.
    I'm researching why the conditional formatting does not automatically update.

  30. #30
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    I would like the array that is produced from the macro running to be unlocked. The array is still locked and I want to be able to enter data manually.

  31. #31
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Example of the formatting issue. See attached
    Last edited by Longbow 44; 03-20-2023 at 09:43 PM.

  32. #32
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    That's strange it works now go figure

  33. #33
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Is it possible to add two more formatting conditions to the array that is produced when the macro runs. They are as follows:
    1. In column 5 (E) if any value is >=1900 then turn the font colour red.
    2. In column 6 (F) if any value is >=45000 then turn the font colour red.

  34. #34
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    I would like to know how to calculate two more formulas see example attached. Thx
    Last edited by Longbow 44; 03-23-2023 at 08:33 PM.

  35. #35
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Try this update:

    Please Login or Register  to view this content.
    Last edited by maniacb; 03-20-2023 at 11:41 PM. Reason: Update Range("R2:T9") to Range("R2:T11")

  36. #36
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    As for the formulas for S10 and S11, see if these will do the job.

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Formula: copy to clipboard
    Please Login or Register  to view this content.

  37. #37
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Can you change cell fill to red and font colour to white please hard to read when blue formatting is executed from an x being placed in source document.


    Please Login or Register  to view this content.
    Last edited by Longbow 44; 03-21-2023 at 07:01 PM.

  38. #38
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Just to clarify I am looking at data in column N/M,O. I need to count/unique but take into account who has still work in progress. See attached
    Last edited by Longbow 44; 03-21-2023 at 09:28 PM.

  39. #39
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Here are the changes you came up with for the conditional formats you asked about before. Great job on them.

    Please Login or Register  to view this content.
    As for the formulas, did you try the solutions in post #36? I based those formulas on column K since that value appears to be the one that designates if any work is still outstanding.

    Note: For future reference, this site asks that any code posted in the thread be encircled by code tags. You can do that by highlighting the code and then selecting the # in the menu bar above the text box.

  40. #40
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    I was wondering if you could make a few more changes for me, please see attached. I was able to change some of the code myself please check it.
    Please Login or Register  to view this content.
    Last edited by Longbow 44; 03-23-2023 at 08:35 PM.

  41. #41
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    1. I got the formulas to work in U10 and U11. Please add dynamic ranges to them.
    U10:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    U11:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    2. I added column "Q/R/S" I changed the code please check my work.

    3. If there is data in the rows I need column R to display "RUN S/A". Please format font and fill white/red. Done See red items below.

    4. If there is a "Y" in column "S', I need column "R" to display "COMPLETED" Please format font and fill white/green.
    For this item, I added code to embed VBA into the new workbook so that anytime the y is entered into column S, column R will be updated. See blue items

    5. Please write this into the code.

    6. I reincluded items we previously wrote into the code. Not sure if you meant to exclude them. See Green items.

    Here is the updated code:

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by maniacb; 03-22-2023 at 05:02 PM.

  42. #42
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Awesome job can't thank you enough for all your hard work. Is it possible to change the file name when it saves the file like this
    (DB-22-03-2023-Wednesday)?
    Please Login or Register  to view this content.
    Do you do that on this line of code? I know you can just save as and change the file name but I was wondering if this is possible.

    Also I need the macro to fill the day and date in when it runs in "k:171",but only once when macro runs (example Wednesday March 3, 2023). I know that excel has a formula you can insert that will change that date to the current one every time you open the file. I do not want the date changed if you open the file at a later date.
    Last edited by Longbow 44; 03-22-2023 at 07:26 PM.

  43. #43
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Yes this is where the file name is assigned. Try:

    Please Login or Register  to view this content.
    include the following line before the .protect:

    Please Login or Register  to view this content.

  44. #44
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Here is the new formula with some minor code changes to freeze, protect, and ranges to copy new tables (please leave in). You removed c5 and c6 and formatting for weight and size, which I would like how it is in the example attached. When I try to add the new code it errors so could you please make it work with the old code (atachement below). Again thank you and sorry to be a bother.

    Also with the new macro you wrote say you make a mistake, and you delete "Y" it does not change back to "RUN S/A". Can you change this so it does?
    Last edited by Longbow 44; 03-23-2023 at 08:36 PM.

  45. #45
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Updates are made and all our previous work has been incorporated. I had added new requests to the file uploaded in post #40, and since that was an older file code, some of the previous enhancements were left out. This code addresses all your questions to date. One question you had was where would the new file be created. It will always be created in the file where this template resides.

    Please Login or Register  to view this content.

  46. #46
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Thank you the code change. I am having problems with the formulas working in u10 u11 u157 u158. With the data entered in example u10 should result 1 since there is only one emp with 2 tasks currently working. The formula in U11 should be 3 since 3 emp worked that day. Same u 157 and u158. Is there something in the cells it is picking up that I am not seeing?

    Also when the macro runs and auto hides the rows it cuts t10:t11 can you fix this please.
    Last edited by Longbow 44; 03-24-2023 at 01:02 AM.

  47. #47
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Here are the updated formulas. Counta counts cells if they are not empty, and since the fields in Col A have a formula in them, they count those cells and include the blank space in Col M as a unique item. So instead let's use the Count function that counts numbers.
    U10:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    U11:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    U157:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    U158:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    To fix the hiding too many rows, update this line of code:

    Please Login or Register  to view this content.

  48. #48
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    I think U 157 has to be counta since I want to know how many emp's are on task and how many worked in dept. See attached

  49. #49
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    You're right. I think that applies to U158 too. I got carried away with the change for the previous formulas.

  50. #50
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    I still get +1 to totals I'm not sure why column M is picking up anything it looks clear to me.
    Last edited by Longbow 44; 03-23-2023 at 11:40 PM.

  51. #51
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Here are the formulas with a dynamic line count within the 152-170 table. That's what I missed before.

    U157:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    U158:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  52. #52
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    I was wondering can I copy data with some type of formula or does it need code if (if I add a column T) and if there is an x found . If this is true I copy the information to rows starting in b 173 and b 174 since there is an x in t2 and t5. I only want information from columns B:F and H:J. This will happen after the macro runs and some manual data is entered.
    Last edited by Longbow 44; 03-24-2023 at 04:26 PM.

  53. #53
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Yes, you're in luck. With O365, you can use the Filter and choose functions. Make sure all the contents of range A172 to M191 is cleared. Then in A173 enter

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    That was fun.

  54. #54
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Here is the code with updates. I left the formula solution in place since column G is not needing a formula. I included unlocking the cells in the worksheet change code so that protection continues to work after a worksheet change executes. I did shift the bottom table over by one column. I made sure all the formatting for copied over table areas are aligned as well.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  55. #55
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    I see its a formula
    Last edited by Longbow 44; 03-24-2023 at 09:51 PM.

  56. #56
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Disregard this post
    Last edited by Longbow 44; 03-24-2023 at 09:51 PM.

  57. #57
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    I updated the code to enter the data into table A172-M191 through a change sheet event instead of using the formula. Updating column M made use of the formula difficult. That code is in red. I'm waiting on clarification on the criteria for the color assignments into Table A172-M191

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by maniacb; 03-27-2023 at 12:28 AM. Reason: Added the .Protect line into the change sheet module

  58. #58
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    See attached for explanation
    Last edited by Longbow 44; 03-24-2023 at 11:21 PM.

  59. #59
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    This works thank you with my conditional formatting. Nothing else required

  60. #60
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Could you please run the sample macro attached with the two source files #1 and #2 attached.
    The output from source #1 is 81 rows of data copied which is correct but when you run source #2 it copies 72 rows plus 1 blank one for 73. Curious why this is happening. It should only be 72.
    Last edited by Longbow 44; 03-27-2023 at 11:50 PM.

  61. #61
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    It looks like "Sample source # 2" had data previously in row 75. Since that data was cleared and the row not deleted, Excel sees it as a row that should be counted in the data, even though it is blank. If you were to select and delete that row and rerun the code, that final empty row will not show up in the data transfer. System generated source files should not have this scenario.

  62. #62
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    To get the file name to appear like:

    DB Monday, March 27, 2023

    Update the Filename line to:

    Please Login or Register  to view this content.

  63. #63
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Thank you for the quick reply

  64. #64
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Maniacb let me know the following is possible. See output attachment for explanation. Thx
    Last edited by Longbow 44; 03-30-2023 at 12:01 AM.

  65. #65
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Your request, to obtain the next value of column M when a "w" is listed in column 16, can be achieved by adding the code highlighted in red into the original code.

    Please Login or Register  to view this content.

  66. #66
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Thank you

  67. #67
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    I didn't realize you still needed the "RUN..." code in that row, below is how you add it in red. For the protection, that code is written in below as well in green.

    Please Login or Register  to view this content.

  68. #68
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Thank you!

  69. #69
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    @ maniacb please look at attachement.
    Last edited by Longbow 44; 04-04-2023 at 11:06 PM.

  70. #70
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Here you go. New lines of code highlighted in red, moved line (The .Protect line) highlighted in blue.

    Please Login or Register  to view this content.
    Note: When testing with the most recent test file in post #69, make sure to delete text box containing instructions.
    Last edited by maniacb; 04-04-2023 at 08:51 AM. Reason: Added Note

  71. #71
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Thank you

  72. #72
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Here is the code with the additional requests:
    Forgot to mention to have code rerun auto hide. When a user adds or deletes a row. I decided that the source would always have enough data so I do not require k +2 to add 2 rows. The two tables can be tight to one another.
    So could it be if you hit control A for add a row and control D to delete a row?
    Also renumber rows in column A ascending order (1-21) and copy 'run/sa' in column 'r'. Also correct any rows that the height gets changed due to pasting. I would like the row height to be 15
    For delete a row the user would hit control D and a message box would come up select what row to delete. The user would then delete the row and the code would adjust count in column A.

    * I also noted that the last template that was shared moved the bottom table down by two rows. I updated the code to update the data on the sheet correctly.

    Please Login or Register  to view this content.

  73. #73
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    A big thanks
    Last edited by Longbow 44; 04-08-2023 at 06:26 PM.

  74. #74
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Alright, here you go. I did some basic testing but I'm not sure what your most current Template looks like. Changes requested in #72 are in red. I also added a basic error trap so that if the code errors out, the user can recover. I got an error when I tried loading the wrong source file. I figure the users could do that too.

    Please Login or Register  to view this content.
    Last edited by maniacb; 04-08-2023 at 09:56 AM. Reason: Updated code with error trap

  75. #75
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Thank you
    Last edited by Longbow 44; 04-09-2023 at 06:06 PM.

  76. #76
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Here is the code without the print lines. The RUN S/A does get updated when a line is added with this code.

    Please Login or Register  to view this content.

  77. #77
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Here is the code with the change to prevent blue/yellow formatting applied to newly added row. I also added to the inputbox the selected row number.

    Please Login or Register  to view this content.

  78. #78
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    This code includes an update to limit row additions to rows 3 to 148 on the template, highlighted in red.

    Please Login or Register  to view this content.

  79. #79
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Thank you

  80. #80
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    @maniacb

    Thank you!
    Last edited by Longbow 44; 05-01-2023 at 06:35 PM.

  81. #81
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    For the Password issue, you only need to add the password to the unprotect line. That line should look like:

    Please Login or Register  to view this content.

  82. #82
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    As for the error, I can't duplicate the error. Since we have an error trapping line, the error notice may not be telling you what the actual issue is. Comment out the trap line (Put an ' in front of the On Error GoTo Trap line) temporarily with an apostrophe and then you will see where the error is located.

  83. #83
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Thank you!
    Last edited by Longbow 44; 05-02-2023 at 10:59 PM.

  84. #84
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Yes, there is a way. Try adding the following redim line into the code:

    Please Login or Register  to view this content.

  85. #85
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Thank you!

  86. #86
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Thank you
    Attached Files Attached Files
    Last edited by Longbow 44; 05-04-2023 at 07:24 PM.

  87. #87
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Alright, here are the updates. New lines highlighted in red. Let me know if you have any questions. The only possible issue I can foresee is if the new lines plus the data add up to greater than 148. Do you think that might happen?
    Please Login or Register  to view this content.

  88. #88
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    @maniacb

    Big thanks!
    Last edited by Longbow 44; 05-06-2023 at 06:57 PM.

  89. #89
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Here are the updates, in red. The code in blue is what closes the VBA code window.

    Please Login or Register  to view this content.

    FYI, this thread has apparently reached its length limit, so new request will probably need a new thread.

  90. #90
    Forum Expert
    Join Date
    05-29-2020
    Location
    NH USA
    MS-Off Ver
    365
    Posts
    2,103

    Re: Copy info from excel file to a template

    Here is another line to update. Change

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.

  91. #91
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    Thank you sir

  92. #92
    Forum Contributor
    Join Date
    03-15-2023
    Location
    Seattle, USA
    MS-Off Ver
    Office 365 subscription V2305
    Posts
    138

    Re: Copy info from excel file to a template

    @maniacb

    Is it possible to hide this part of the code (below) from the user? When the user runs the macro and the array is created, the user can still view part of the code (and they can find out what the protect password is). Can you show me how to password protect it (Microsoft Excel Objects Sheet1) like I have done for (module 1) in the template? My guess is it needs to be written into the code.

    Please Login or Register  to view this content.
    Last edited by Longbow 44; 05-13-2023 at 08:22 PM.

+ 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. [SOLVED] Copy 4 sheets from template and dynamically name, Save template and leave workin file open
    By Webbers in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-29-2019, 02:39 PM
  2. Replies: 0
    Last Post: 12-21-2015, 05:10 AM
  3. Macro to Copy Info from a PDF File to excel
    By danallamas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-18-2015, 04:28 PM
  4. Replies: 2
    Last Post: 02-10-2014, 11:52 AM
  5. Replies: 3
    Last Post: 05-15-2013, 11:34 PM
  6. copy info another excel file
    By Halid in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-14-2013, 02:50 AM
  7. Copy info from cell in template
    By susanhamm in forum Excel General
    Replies: 7
    Last Post: 11-23-2011, 04:33 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