If Condition Is Not Met Then Exit Sub

  • hi,

    i was wondering how i would write the below

    i have a workbook which i wish to open however if data on sheet 1 does not have current days date in column b then exit sub so it needs to look at sheet 1 of workbook called "aims" and if the data in column b does not = current days date then exit if it does then carry on through code.?


    is it also possible to open a workbook that will be named (ddmmyyAims), from a certain directory?..ie it will always have name format at end but the date will change to current day?..how would i write this. also if id doesnet equal this then exit sub and error messaqge" filename can not be found"

    i realise this is two questions but they are simlar in nature...i think

    thx very much if anyone can help

  • Re: If Condition Is Not Met Then Exit Sub

    Hello hadlee,

    Assuming your date may be in cell B1 then

    Sub MyProcedure()
        If Range("B1") <> Date Then
            Exit Sub
        End If
        'other code
    End Sub

    Hope this helps


    [FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
    Tip: To avoid chasing code always use Option Explicit.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!