+ Reply to Thread
Results 1 to 3 of 3

Bypass procedure if date falls within a given range of dates

  1. #1
    Registered User
    Join Date
    03-14-2016
    Location
    Scotland
    MS-Off Ver
    2010
    Posts
    13

    Bypass procedure if date falls within a given range of dates

    Hi all, i have a loop which is supposed to move on to the next step in the loop if a given date exists in a range held on another tab (i.e. bypass the procedure to be carried out) but this does not happen even though the the code realises the date does exist in the range (i.e. True is given). I have attached a sample WB but the code is shown below (sorry i/m unable to use code tags - mods are looking into):

    Sub PH()
    'Extract from bigger piece of code
    'Submit Forecast for given task


    Dim FDate As Date
    Dim PH

    PH = "A2:A25"

    For y = 0 To 4 'Loop through columns required to conduct check
    'DEFINE DATES FOR FORECAST (as on WB row 2)
    If y = 0 Then FDate = Sheets("Forecast").Range("F2") 'Monday date
    If y = 1 Then FDate = Sheets("Forecast").Range("H2") 'Tuesday date
    If y = 2 Then FDate = Sheets("Forecast").Range("J2") 'Wednesday date
    If y = 3 Then FDate = Sheets("Forecast").Range("L2") 'Thursday date
    If y = 4 Then FDate = Sheets("Forecast").Range("N2") ' Friday date

    'DEFINE DAY FOR FORECAST (as on WB row 1) & NOTE COLUMN REFERENCE
    If y = 0 Then DoW = "Mon"
    If y = 1 Then DoW = "Tue"
    If y = 2 Then DoW = "Wed"
    If y = 3 Then DoW = "Thu"
    If y = 4 Then DoW = "Fri"
    DoWCol = Application.WorksheetFunction.Match(DoW, Rows(1), 0)

    'CHECK IF F DATE IS A PUBLIC HOLIDAY AND IF SO - SKIP THIS STEP AND MOVE TO NEXT COLUMN
    If Application.CountIf(Range(PH), FDate) > 0 Then GoTo PubHol

    For x = 1 To 5
    Cells(x + 8, DoWCol) = "Volume here"
    Next x

    PubHol: 'Move to next column
    Next y
    Exit Sub
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Bypass procedure if date falls within a given range of dates

    PH = "A2:A25"
    This range had no sheet qualifier. So it defaults to a range on the active sheet.

    This will qualify the "Control Sheet for the holiday list.
    PH = "Control!A2:A25"


    A formula like this in F9 and drag down could do the same.
    =IF(ISERROR(MATCH(F$2,Control!$A:$A,0)),"Volume Here", "")
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Bypass procedure if date falls within a given range of dates

    Here's another version of your code.

    Please Login or Register  to view this content.

+ 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. Sum if date falls between two dates
    By pauldaddyadams in forum Excel General
    Replies: 1
    Last Post: 09-10-2015, 02:07 PM
  2. [SOLVED] Check a date to find if it falls between a range of dates
    By Kausch in forum Excel General
    Replies: 3
    Last Post: 10-21-2014, 07:56 AM
  3. Replies: 12
    Last Post: 06-13-2014, 05:03 PM
  4. [SOLVED] Returning a date from a range if date falls between two other dates
    By sdavison in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 06-25-2013, 03:59 AM
  5. [SOLVED] Value with Corresponding Date if Falls Within Range of Dates
    By ebdmbfan in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-26-2012, 09:14 AM
  6. Replies: 3
    Last Post: 05-30-2011, 01:37 PM
  7. returning a value if a date falls between two dates
    By chillangella in forum Excel General
    Replies: 3
    Last Post: 09-28-2009, 06:51 AM

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