PC Review


Reply
Thread Tools Rate Thread

Code in a macro to branch to another macro?

 
 
Kevryl
Guest
Posts: n/a
 
      24th Apr 2010
I wonder if someone can help me with a little code for inclusion in a macro?
It needs to do the following:

“If cell in column D on this row = "Sunday", perform Macro “Sunday”,
otherwise execute macro “Weekday””

Background info:

I run an accounting system on a series of worksheets. The Cash Journal
dynamically applies the week of the year and day of the week (based on the
first date in the financial year) and conditionally formats rows accordingly
to highlight weekends. Macros post the daily cashup sheet to the Cash
Journal and General journal. I am combining them to operate both from the
Cashup sheet and I need that macro to automatically avoid posting to a row in
the Cash Journal that falls on Sunday. So it must makes a decision on the day
and branch to an alternate macro on Sunday. (Both macros will be the same,
except that “Sunday” will jump down 2 more rows (cash register inputs) than
“Weekday” before recreating a range name that acts as a cursor locator.)

Many thanks
Kevryl

 
Reply With Quote
 
 
 
 
JLatham
Guest
Posts: n/a
 
      24th Apr 2010
Do you have any code written at all yet? First, I'd advise on not using
"Weekday" as the name of a macro (and to a lesser degree I wouldn't use
Sunday either). Perhaps something like "ProcessSundays" and "ProcessWeedays".

But to your specific question:
Sub MakeTheDecision()
If ThisWorkbook.Worksheets("SheetName").Range("D5") = _
"Sunday" Then
ProcessSundays
Else
ProcessWeekdays
End If
End Sub

That code assumes that it is in the same module with the two referenced Subs.

"Kevryl" wrote:

> I wonder if someone can help me with a little code for inclusion in a macro?
> It needs to do the following:
>
> “If cell in column D on this row = "Sunday", perform Macro “Sunday”,
> otherwise execute macro “Weekday””
>
> Background info:
>
> I run an accounting system on a series of worksheets. The Cash Journal
> dynamically applies the week of the year and day of the week (based on the
> first date in the financial year) and conditionally formats rows accordingly
> to highlight weekends. Macros post the daily cashup sheet to the Cash
> Journal and General journal. I am combining them to operate both from the
> Cashup sheet and I need that macro to automatically avoid posting to a row in
> the Cash Journal that falls on Sunday. So it must makes a decision on the day
> and branch to an alternate macro on Sunday. (Both macros will be the same,
> except that “Sunday” will jump down 2 more rows (cash register inputs) than
> “Weekday” before recreating a range name that acts as a cursor locator.)
>
> Many thanks
> Kevryl
>

 
Reply With Quote
 
Kevryl
Guest
Posts: n/a
 
      24th Apr 2010
Hi JL, thanks for such a fast response.

Yes & No - no code for the Sunday decision but the very lengthy macros to be
combined have been running smoothly every day for about 6 years.

The names: just used Saturday and Sunday for ease of explanation. I shall
take your advice on that. I'm surprised that "ProcessSundays" doesn't need to
be inside quotes or brackets.

One problem remains: "Range("D5")" in your code is absolute, and it needs to
be relative to travel down the sheet. The cursor will be in column E (at
rangename "CJreturn" at the point when it refers to the contents of Column C.
I could use the same name/delete/rename routine that I use for "CJreturn" to
advance the cursor begin point, and address the rangename, but there's
probably a tidier way. Will that work, just substituting (say) the rangename
"daycheck" for "D5" in the code you have given? I reckon it should.

Well, its 1.00am Sunday here in Tasmania and I gotta go home! I presume its
late Saturday afternoon where you are so have a great evening!

Thanks again.

"JLatham" wrote:

> Do you have any code written at all yet? First, I'd advise on not using
> "Weekday" as the name of a macro (and to a lesser degree I wouldn't use
> Sunday either). Perhaps something like "ProcessSundays" and "ProcessWeedays".



>
> But to your specific question:
> Sub MakeTheDecision()
> If ThisWorkbook.Worksheets("SheetName").Range("D5") = _
> "Sunday" Then
> ProcessSundays
> Else
> ProcessWeekdays
> End If
> End Sub
>
> That code assumes that it is in the same module with the two referenced Subs.
>
> "Kevryl" wrote:
>
> > I wonder if someone can help me with a little code for inclusion in a macro?
> > It needs to do the following:
> >
> > “If cell in column D on this row = "Sunday", perform Macro “Sunday”,
> > otherwise execute macro “Weekday””
> >
> > Background info:
> >
> > I run an accounting system on a series of worksheets. The Cash Journal
> > dynamically applies the week of the year and day of the week (based on the
> > first date in the financial year) and conditionally formats rows accordingly
> > to highlight weekends. Macros post the daily cashup sheet to the Cash
> > Journal and General journal. I am combining them to operate both from the
> > Cashup sheet and I need that macro to automatically avoid posting to a row in
> > the Cash Journal that falls on Sunday. So it must makes a decision on the day
> > and branch to an alternate macro on Sunday. (Both macros will be the same,
> > except that “Sunday” will jump down 2 more rows (cash register inputs) than
> > “Weekday” before recreating a range name that acts as a cursor locator.)
> >
> > Many thanks
> > Kevryl
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning macro buttons to macro code in another file Enz Microsoft Excel Programming 2 25th May 2009 06:44 PM
Write a branch to another macro iashorty Microsoft Excel Worksheet Functions 4 10th Apr 2008 01:40 AM
Can I use code/macro to change code/macro in an existing file? =?Utf-8?B?U2NvdHQgQmVkb3dz?= Microsoft Excel Programming 2 14th Feb 2007 05:50 AM
Fax Report Via Macro, See Attached Macro Code (Need Help With This) Dave Elliott Microsoft Access Forms 0 4th Nov 2003 07:21 AM
Adding macro code to Personal Macro Workbook mika Microsoft Excel Misc 2 16th Oct 2003 09:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:13 AM.