+ Reply to Thread
Results 1 to 19 of 19

Can this VBA be simplified

  1. #1
    Forum Contributor Toonies's Avatar
    Join Date
    07-30-2009
    Location
    Newcastle, UK
    MS-Off Ver
    Excel 2016
    Posts
    511

    Can this VBA be simplified

    Hi and thanks for looking at my thread.

    I have the following VBA and it changes the dates on different sheets when the date is changed on the "DATE" sheet

    the VBA does the job just wondering if it can be simplified.
    heres the code

    Please Login or Register  to view this content.
    many thanks

    Toonies

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Can this VBA be simplified

    Please Login or Register  to view this content.
    If solved remember to mark Thread as solved

  3. #3
    Forum Contributor Toonies's Avatar
    Join Date
    07-30-2009
    Location
    Newcastle, UK
    MS-Off Ver
    Excel 2016
    Posts
    511

    Re: Can this VBA be simplified

    Hi thanks for your suggestion, though it throughs up errors

    Run-time error '1004':

    Select method of Worksheet class failed

    this is the problem line

    Please Login or Register  to view this content.

    also the date should change by 1 in each cell within the range on each sheet

    ie: each sheet is 7 days ahead of the previous sheet

  4. #4
    Forum Contributor Toonies's Avatar
    Join Date
    07-30-2009
    Location
    Newcastle, UK
    MS-Off Ver
    Excel 2016
    Posts
    511

    Re: Can this VBA be simplified

    I'm open to any further ideas

  5. #5
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Can this VBA be simplified

    Maybe this

    Please Login or Register  to view this content.
    Last edited by mike7952; 12-26-2012 at 08:16 AM.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

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

    Re: Can this VBA be simplified

    Untested
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor Toonies's Avatar
    Join Date
    07-30-2009
    Location
    Newcastle, UK
    MS-Off Ver
    Excel 2016
    Posts
    511

    Re: Can this VBA be simplified

    Hi AB33 your code is like my original code that I am looking to reduce.

    mike7592 I amended your code to the following

    Please Login or Register  to view this content.
    also the date should change by 1 in each cell within the range on each sheet (ie: each sheet starts 7 days ahead of the previous sheet)

    but however with the amended code it is putting the same 7 dates on each sheet.

  8. #8
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: Can this VBA be simplified

    With your amending theres no reason to loop thru 2 to 10. Your selecting all the sheets already.

    Please Login or Register  to view this content.

  9. #9
    Forum Contributor Toonies's Avatar
    Join Date
    07-30-2009
    Location
    Newcastle, UK
    MS-Off Ver
    Excel 2016
    Posts
    511

    Re: Can this VBA be simplified

    here is a copy of the spreadsheet

    Demo 1a.xls

  10. #10
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Can this VBA be simplified

    You can simplify this section:

    Please Login or Register  to view this content.
    To:

    Please Login or Register  to view this content.

  11. #11
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Can this VBA be simplified

    And this section:

    Please Login or Register  to view this content.
    Can be reduced to:

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor Toonies's Avatar
    Join Date
    07-30-2009
    Location
    Newcastle, UK
    MS-Off Ver
    Excel 2016
    Posts
    511

    Re: Can this VBA be simplified

    Hi Andrew-R

    I get a Run Time error '13'

    and this part of the code is highlighted

    Please Login or Register  to view this content.

  13. #13
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Can this VBA be simplified

    Sorry, the final "*" should be an "&"

  14. #14
    Forum Contributor Toonies's Avatar
    Join Date
    07-30-2009
    Location
    Newcastle, UK
    MS-Off Ver
    Excel 2016
    Posts
    511

    Re: Can this VBA be simplified

    Ok now I have got that to work but it still populates each sheet with the same 7 dates

    in my original code it populated each sheet with a with 7 dates each sheet dates 1 week ahead of the previous sheets starting date

    hope I'm explaining myself correctly

  15. #15
    Forum Contributor Toonies's Avatar
    Join Date
    07-30-2009
    Location
    Newcastle, UK
    MS-Off Ver
    Excel 2016
    Posts
    511

    Re: Can this VBA be simplified

    Hi I'm still open to ideas

  16. #16
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Can this VBA be simplified

    hi there, the code inbetween the following two lines:

    Please Login or Register  to view this content.
    can be replaced with the following:

    Please Login or Register  to view this content.
    Last edited by watersev; 12-26-2012 at 06:41 PM.

  17. #17
    Forum Contributor Toonies's Avatar
    Join Date
    07-30-2009
    Location
    Newcastle, UK
    MS-Off Ver
    Excel 2016
    Posts
    511

    Re: Can this VBA be simplified

    Watersev now thats a cool bit of coding many thanks it works a treat

    could you explain how it actually works

    thanks

    Toonies

  18. #18
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: Can this VBA be simplified

    loop from Sheet "Sheet2" till sheets count, for each sheet an array is filled with formulas and pasted to the sheet

  19. #19
    Forum Contributor Toonies's Avatar
    Join Date
    07-30-2009
    Location
    Newcastle, UK
    MS-Off Ver
    Excel 2016
    Posts
    511

    Re: Can this VBA be simplified

    Many thanks


+ 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