Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default trying to find the previous thursday before running a macro

The title pretty much says it all. I am trying to find the previous thursday
that occur before I run a macro. The previous thursday date is part of the
file name, so I need that to open the previous file. Most of the time I will
run the macro on Wednesday, so something like now()-6 could work, but I would
rather not make it not day dependent.

Thanks,
B
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default trying to find the previous thursday before running a macro

Brian.

I assume that if 'Today' is Thursday you want todays date or if nit the
previous Thursday.

LastThursday = Date + WorksheetFunction.Choose(Weekday(Date), -3, -4, -5,
-6, 0, -1, -2)
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Brian S" wrote:

The title pretty much says it all. I am trying to find the previous thursday
that occur before I run a macro. The previous thursday date is part of the
file name, so I need that to open the previous file. Most of the time I will
run the macro on Wednesday, so something like now()-6 could work, but I would
rather not make it not day dependent.

Thanks,
B

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default trying to find the previous thursday before running a macro

Hi,

I should have added if you want the previous Thursday even if today is
Thursday then change the 0 (Zero) in the formula to -7
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Mike H" wrote:

Brian.

I assume that if 'Today' is Thursday you want todays date or if nit the
previous Thursday.

LastThursday = Date + WorksheetFunction.Choose(Weekday(Date), -3, -4, -5,
-6, 0, -1, -2)
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Brian S" wrote:

The title pretty much says it all. I am trying to find the previous thursday
that occur before I run a macro. The previous thursday date is part of the
file name, so I need that to open the previous file. Most of the time I will
run the macro on Wednesday, so something like now()-6 could work, but I would
rather not make it not day dependent.

Thanks,
B

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default trying to find the previous thursday before running a macro

Two things... First, VB has its own built-in Choose function, so you don't
have to call out to the worksheet's version of the function. Second, you can
use a straight calculation rather than using the Choose function...

LastThursday = Date + 1 - Weekday(Date, vbThursday)

--
Rick (MVP - Excel)



"Mike H" wrote in message
...
Brian.

I assume that if 'Today' is Thursday you want todays date or if nit the
previous Thursday.

LastThursday = Date + WorksheetFunction.Choose(Weekday(Date), -3, -4, -5,
-6, 0, -1, -2)
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Brian S" wrote:

The title pretty much says it all. I am trying to find the previous
thursday
that occur before I run a macro. The previous thursday date is part of
the
file name, so I need that to open the previous file. Most of the time I
will
run the macro on Wednesday, so something like now()-6 could work, but I
would
rather not make it not day dependent.

Thanks,
B


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default trying to find the previous thursday before running a macro

Rick,

I forgot about Choose in Vb, thank's for that.

The reason i did it that way was I wasn't sure what the OP wanted if it was
Thursday, did he want 'today' or 7 days earlier i.e the previous Thursday.
How would you change your code to provide the latter?
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Rick Rothstein" wrote:

Two things... First, VB has its own built-in Choose function, so you don't
have to call out to the worksheet's version of the function. Second, you can
use a straight calculation rather than using the Choose function...

LastThursday = Date + 1 - Weekday(Date, vbThursday)

--
Rick (MVP - Excel)



"Mike H" wrote in message
...
Brian.

I assume that if 'Today' is Thursday you want todays date or if nit the
previous Thursday.

LastThursday = Date + WorksheetFunction.Choose(Weekday(Date), -3, -4, -5,
-6, 0, -1, -2)
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Brian S" wrote:

The title pretty much says it all. I am trying to find the previous
thursday
that occur before I run a macro. The previous thursday date is part of
the
file name, so I need that to open the previous file. Most of the time I
will
run the macro on Wednesday, so something like now()-6 could work, but I
would
rather not make it not day dependent.

Thanks,
B


.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default trying to find the previous thursday before running a macro

Thanks for the responses. Mikes worked so I didn't try yours Rick.

Yes if today is Thursday I still wanted it to show the previous thursday.

Thanks again.
Brian

"Mike H" wrote:

Rick,

I forgot about Choose in Vb, thank's for that.

The reason i did it that way was I wasn't sure what the OP wanted if it was
Thursday, did he want 'today' or 7 days earlier i.e the previous Thursday.
How would you change your code to provide the latter?
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Rick Rothstein" wrote:

Two things... First, VB has its own built-in Choose function, so you don't
have to call out to the worksheet's version of the function. Second, you can
use a straight calculation rather than using the Choose function...

LastThursday = Date + 1 - Weekday(Date, vbThursday)

--
Rick (MVP - Excel)



"Mike H" wrote in message
...
Brian.

I assume that if 'Today' is Thursday you want todays date or if nit the
previous Thursday.

LastThursday = Date + WorksheetFunction.Choose(Weekday(Date), -3, -4, -5,
-6, 0, -1, -2)
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Brian S" wrote:

The title pretty much says it all. I am trying to find the previous
thursday
that occur before I run a macro. The previous thursday date is part of
the
file name, so I need that to open the previous file. Most of the time I
will
run the macro on Wednesday, so something like now()-6 could work, but I
would
rather not make it not day dependent.

Thanks,
B


.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default trying to find the previous thursday before running a macro

I guess this would suffice...

LastThursday = D + 1 + 7 * (Weekday(D) = 5) - Weekday(D, vbThursday)

--
Rick (MVP - Excel)



"Mike H" wrote in message
...
Rick,

I forgot about Choose in Vb, thank's for that.

The reason i did it that way was I wasn't sure what the OP wanted if it
was
Thursday, did he want 'today' or 7 days earlier i.e the previous Thursday.
How would you change your code to provide the latter?
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Rick Rothstein" wrote:

Two things... First, VB has its own built-in Choose function, so you
don't
have to call out to the worksheet's version of the function. Second, you
can
use a straight calculation rather than using the Choose function...

LastThursday = Date + 1 - Weekday(Date, vbThursday)

--
Rick (MVP - Excel)



"Mike H" wrote in message
...
Brian.

I assume that if 'Today' is Thursday you want todays date or if nit the
previous Thursday.

LastThursday = Date +
WorksheetFunction.Choose(Weekday(Date), -3, -4, -5,
-6, 0, -1, -2)
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis
that
introduces the fewest assumptions while still sufficiently answering
the
question.


"Brian S" wrote:

The title pretty much says it all. I am trying to find the previous
thursday
that occur before I run a macro. The previous thursday date is part
of
the
file name, so I need that to open the previous file. Most of the time
I
will
run the macro on Wednesday, so something like now()-6 could work, but
I
would
rather not make it not day dependent.

Thanks,
B


.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to delete previous data from 1 macro before running the next? KS-Macro Excel Programming 4 September 22nd 09 07:43 PM
Find used range and ignore blank cells when running macro? Rick S. Excel Programming 3 October 3rd 07 02:52 PM
Find the previous Weekday (thursday) JimDandy Excel Worksheet Functions 4 August 10th 06 07:25 PM
how can i find out which macro is running mel535 Setting up and Configuration of Excel 0 March 29th 06 04:59 PM
Cannot find file when running macro xgirl Excel Programming 1 December 28th 05 07:12 PM


All times are GMT +1. The time now is 06:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"