+ Reply to Thread
Results 1 to 28 of 28

Macro to update worksheets

  1. #1
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    195

    Macro to update worksheets

    Does anyone know a macro I can use that will update sheet 1-4 from the information in sheet5? I have updated Sheet1 with what I need the macro to do from the data.
    Attached Files Attached Files

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to update worksheets

    Hi eoghanmolloy

    Try this Code in a General Module
    Please Login or Register  to view this content.
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    195

    Re: Macro to update worksheets

    Thanks for that...works perfectly

  4. #4
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    195

    Re: Macro to update worksheets

    I've had to make some changes with the data source and layout which will affect the code above. Please see attahced files. Can you let me know what the new code should be?
    Attached Files Attached Files
    Last edited by eoghanmolloy; 12-12-2012 at 08:14 AM.

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to update worksheets

    Hi eoghanmolloy

    It's a major rewrite. Before I start are there any more changes?

  6. #6
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    195

    Re: Macro to update worksheets

    Hi John,

    Apologies, I persumed it wouldn't be too much of a hassle to change the coding if the data source was in a different spreadsheet. Thanks for taking your time to do this.

    The only changes that I will need to make to the completed code is the file name of the spreadsheets and A9 of Test2 will not be called 'Code' and the same with B5 of Test1. There will also be about 90 worksheets that will need updating compared with the 4 example ones I have on Test1.

    Will these changed have any major impact on the code apart from small editing changes?

    Thanks,

    Eoghan

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to update worksheets

    Hi Eoghan
    What will be the Sheet Names in Test1? Will they be the SAME AS the Names in Column A of Test2?

  8. #8
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    195

    Re: Macro to update worksheets

    Hi John,

    Yes, the Names in Column A of Test2 will have a Sheet named after it in Test1. I don't know if it will make a difference but the codes will not be AAA,BBB, etc - they will be 4 character codes mixtures of letters and numbers.

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to update worksheets

    Hi Eoghan
    This does not matter as long as they're all spelled correctly and don't have invalid Characters
    Please Login or Register  to view this content.
    Let me play with it.

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to update worksheets

    Hi Eoghan

    The code runs from Test1, Module1 and assumes both files are in the same directory. The code can be changed if the files are NOT in the same directory.

    Modify these variables as required
    Please Login or Register  to view this content.
    Test2 can be open or closed...doesn't matter. Let me know of issues.
    Attached Files Attached Files

  11. #11
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    195

    Re: Macro to update worksheets

    Hi John,

    I have updated the code as follows but a 'Complie Error: Variable not defined.' occurs. Can you let me know what I need to change? Thanks.

    Please Login or Register  to view this content.

  12. #12
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to update worksheets

    Hi Eoghan

    My best guess is these two lines of code...no variable is defined
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    195

    Re: Macro to update worksheets

    Hi John,

    Do you know how I can change it so the macro works?

  14. #14
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to update worksheets

    Hi Eoghan

    Is this not the Original code from Post #2 (as modified by you)? Simply use that code...or, tell me what you're trying to do.

    This is NOT the code from Post #10 which assumes two workbooks.

  15. #15
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    195

    Re: Macro to update worksheets

    Apologies John I completely missinterpreted what you said in message 10! For some reason I did not see the two amended spreadsheets you had uploaded. Problem solved! Thanks!

  16. #16
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to update worksheets

    Hi Eoghan

    No apology necessary...glad you got it sorted.

  17. #17
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    195

    Re: Macro to update worksheets

    Hi John,

    It works fine on the example I posted but when I try to use it on my spreadsheet a "Run-time error '9': Subscript out of range" error appears. I don't know if this is beacuse with the spreadsheet I'm using this macro on has about 90 worksheets? Any ideas/suggestions?

  18. #18
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to update worksheets

    Hi Eoghan

    What line of code is throwing the error? The message implies that the code is looking for something and can't find it. There needs to be a worksheet in Test1 for EVERY name in worksheet Data of test2 AND they need to be spelled the same way.

  19. #19
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    195

    Re: Macro to update worksheets

    The error was on the code below

    Please Login or Register  to view this content.
    This may be a bit of a problem then because the code did not have a worksheet on the Test1 spreadsheet. Is there a way to get round this?

  20. #20
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to update worksheets

    Hi Eoghan

    I suspected that was the issue...let me look at it.

  21. #21
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to update worksheets

    Hi Eoghan

    See if this works for you...replace all the code with this
    Please Login or Register  to view this content.

  22. #22
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to update worksheets

    If you don't want the message let me know.

  23. #23
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    195

    Re: Macro to update worksheets

    Hi John,

    I tried to run this macro in the spreadsheet im using and after about 15 minutes of waiting it crashed. Any ideas of what to do?

  24. #24
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to update worksheets

    Hi Eoghan

    Perhaps break the File down to smaller segments, say from 90 worksheets to 30 or 45? Beyond that...don't know.

  25. #25
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    195

    Re: Macro to update worksheets

    I don't think I can go down the route of breaking the file down. Should I mark this thread as solved and re-post my problem again?

  26. #26
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to update worksheets

    Hi Eoghan

    I don't know what happens when you say
    after about 15 minutes of waiting it crashed
    Do you get an Error Message? Does Excel close? Was Excel not responding? Did you hit the Escape Key to see where the code was in the Procedure? All of these are clues.

    Try the Escape Key when you feel things are not happening...doing that is setting a Break Point in the Code...see if it's still running...let me know. I'd GUESS (only a GUESS) that the File is so large that the Process is going to take a bit.

    Get back to me.

  27. #27
    Forum Contributor
    Join Date
    11-15-2012
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2010
    Posts
    195

    Re: Macro to update worksheets

    Hi John,

    Aplogies I thought I had replied to you - evidently not. After about 10/15 minutes of the macro running Excel is not responding. I think it's because the file is too big and will only get bigger. Is there a different way of writing a macro to solve this problem?

  28. #28
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to update worksheets

    Hi Eoghan

    Not that I'm aware. You may wish to start a new Thread and describe the issue. Perhaps another can help you resolve it.

+ 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