+ Reply to Thread
Results 1 to 9 of 9

Execute one macro from within another ?

  1. #1
    Registered User
    Join Date
    09-24-2008
    Location
    Eureka, Ca
    MS-Off Ver
    Office 2003
    Posts
    21

    Execute one macro from within another ?

    Hi All,
    I've attached a sample sheet here.
    Basically, I've got a caendar that will be created manually for each month.

    The week 1, Week 2, Week 3 etc are all hyperlinks to seperate workbooks where each sheet is for each day of the week (Mon to Fri)

    I've got the macro for clearing each of these weeks already working (no problems there).
    I've also got seperate macros for showing "X"s in the days of Week 1 that are in the previous month (as in this example where Mon to Wed are in June).
    I'll also have macros to do the same thing for Week 5 where days of the week are in the following month.

    Right now I create the calendar by hand, run the macro to clear all of the 5 weekly workbooks & then depending on what day of week 1 is the First of the month I run one of the macros that will "X" Mon to the day before the First.
    I've got macros to do this where each one clears Mon, Mon & Tues, Mon, Tues, & Wed etc.

    My question is:
    At the end of my code to clear the 5 weeks, can I execute the relevent macro to "X" the blank days of Week 1.
    So basically I'd like a simple piece of code to add on to the end that looks at Friday of week 1, if that isn't blank it looks at Thursday, if that isn't blank it looks at Wednesday & so on back to Monday.
    When it finds the first blank it will run the relevent macro to "X" those days of the workbook Week 1.

    My macros to "X" the days of the week are called
    Blank_Monday_Week_1
    Blank_Tues_Week_1
    etc.

    Hope I've given enough info here - Sorry if it's too much.

    Thanks for any help in advance
    John
    Attached Files Attached Files
    Last edited by Originalgoth; 07-06-2010 at 09:15 AM. Reason: Forgot to set notification of replies option

  2. #2
    Forum Contributor
    Join Date
    05-09-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    315

    Re: Execute one macro from within another ?

    Hi John

    To run one sub from another use

    Call Blank_Monday_Week_1

    Or

    Application.Run "Blank_Monday_Week_1" (if it's a Private Sub)

    Dion

  3. #3
    Registered User
    Join Date
    09-24-2008
    Location
    Eureka, Ca
    MS-Off Ver
    Office 2003
    Posts
    21

    Re: Execute one macro from within another ?

    Hi Dion,
    Thanks for the fast response.

    I've tried putting this code together but without any luck....I know the IF needs work, (at first I had it as)
    Please Login or Register  to view this content.
    But that didn't seem to work at all so I changed it to the below code and now even when E5 isn't empty it still runs the sub Blank_Wed.

    Please Login or Register  to view this content.

    Where am I going wrong ?????????? I know I haven't got a "False" argument on the If statement - I did try Else False on the end of it but it didn't like that.....So then I tried Else End If but it still didn't like that either.

    I was running this code on my working model - not the sample sheet that I attached here.

    I was also getting an error saying "End If without Block If" so right now I have commented out the End If.

    Any help would be appreciated.

    Thanks Again
    John

  4. #4
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Execute one macro from within another ?

    Hi John,

    Try changing the "E5" to Range("E5") [or instead of "E5" you can use ActiveCell since you have already selected "E5"] so that your code will look like this:

    Please Login or Register  to view this content.
    abousetta
    Last edited by abousetta; 07-06-2010 at 02:43 AM.

  5. #5
    Forum Contributor
    Join Date
    05-09-2009
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    315

    Re: Execute one macro from within another ?

    Avoid selecting the cell unless you have to - it slows your macro down.


    Please Login or Register  to view this content.
    Dion

  6. #6
    Registered User
    Join Date
    09-24-2008
    Location
    Eureka, Ca
    MS-Off Ver
    Office 2003
    Posts
    21

    Thumbs up Re: Execute one macro from within another ?

    Thanks Dion & Abousetta,

    With some tweaking of Abousettas' code I've ended up with this and after testing it it works perfectly so now I've tacked it onto the end of the macro I mentioned in my original post & I'm glad to say it does exactly what I wanted it to do.
    I changed your "200" to "x"

    Please Login or Register  to view this content.
    Dion, I took your advice and removed all other Cell References, I only had them in there to get the active cell away from the calendar at the end of the routine.

    Thank you both for your great help on this one.

    I'll mark it as SOLVED and give both of you positive ratings.

    Thanks Again
    John

  7. #7
    Registered User
    Join Date
    09-24-2008
    Location
    Eureka, Ca
    MS-Off Ver
    Office 2003
    Posts
    21

    Re: Execute one macro from within another ?

    Just to add an update to this post:
    I've now completed this project, Thanks for the help.

    What I though I was going to have trouble with was how to "X" out Week 5, but with a little thinking about it I created a Sub Routine called "Clear_Week_5_Sub" and put a call into each part of the previous code to take Week 5 into account at each step.

    I'm happy to say that it works perfectly.
    This is what I ended up with.

    Please Login or Register  to view this content.

    So now, no matter what day of the week a month starts on, while it's checking for that it will also check for the last day of the month in Week 5 and "X" out the days that are in the following month.

    "Clear_Week_5_Sub" is a rework of the original code that works in the reverse order, so it first of all looks at Monday of Week 5, then Tuesday & so on until Friday.

    Thanks again for the help from Dion & Abousetta

    Best Wishes
    John
    Last edited by Originalgoth; 07-06-2010 at 02:30 PM. Reason: Changed Code when I found a bug in the original workbook

  8. #8
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Execute one macro from within another ?

    Glad it all worked out. Good luck on all your projects.

    abousetta

  9. #9
    Registered User
    Join Date
    09-24-2008
    Location
    Eureka, Ca
    MS-Off Ver
    Office 2003
    Posts
    21

    Re: Execute one macro from within another ?

    Thanks Again for your help Abousetta.


+ 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