+ Reply to Thread
Results 1 to 6 of 6

Code not finding previous Monday

  1. #1
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Code not finding previous Monday

    Can anyone see why this is generating a RunTime Error 91? Works perfectly as a formula (=F2-WEEKDAY(F2,2)+1)

    It should check whether the date in F2 (.cells(2,6) is a Monday. If it is, that becomes STARTDAY. If it isn't, the code should find the previous Monday to the date and use THAT as STARTDAY.

    Please Login or Register  to view this content.
    All solutions, suggestions and alternatives welcome as ever

    Ochimus

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Code not finding previous Monday

    I'm guessing STARTDAY should be an Integer.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: Code not finding previous Monday

    Trevor,

    Tried that and it now throws a "Run Time 6 error "Overflow"?

    I'll have to "bodge" it for the moment, put the Formula in F3, which works, and use that as the STARTDAY.

    NOT a Dry Blackrthorn week, this. Still struggling with the "erratic" percentage number in the Front Form and now this.

    Ochimus

  4. #4
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: Code not finding previous Monday

    Try Long or Date rather than Integer Integer will err if the date is later than 16 September 1989 (if you are using the normal 1900 system).
    Last edited by WasWodge; 11-12-2019 at 05:07 AM. Reason: added "or Date"
    If my solution worked (or not) please let me know. If your question is answered then please remember to mark it solved

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Code not finding previous Monday

    Take note of the yellow banner

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,908

    Re: Code not finding previous Monday

    How about this one.

    Please Login or Register  to view this content.
    Last edited by bakerman2; 11-12-2019 at 04:26 AM.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Extract Date for Monday of the previous week
    By JamesT1 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 08-29-2018, 08:26 AM
  2. [SOLVED] Monday is being counted as the previous week?
    By Roan242 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-26-2014, 07:29 AM
  3. [SOLVED] Return the date of the previous Monday
    By pickslides in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-19-2014, 10:01 AM
  4. [SOLVED] Sum from the last Monday of the month previous
    By Berna11 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-17-2013, 03:26 PM
  5. SOLVED - Display the date of the previous Monday?
    By tavlrb in forum Excel General
    Replies: 2
    Last Post: 02-26-2011, 01:50 AM
  6. Finding the date of previous Monday of Certain date
    By Juhanen II in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-04-2009, 08:40 AM
  7. The Monday of the previous week with VBA
    By Gérard Ducouret in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-06-2006, 04:30 PM

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