Help If cell contains certain text run macro if not message box

1nk3d

Board Regular
Joined
May 31, 2016
Messages
51
I have a macro for a workbook, I will post the beginning of the code below. We have a selection sheet (Home) What I need is for if cell G9 on Home says select, a message box to pop up and end, if G9 contains any other text, resume the macro below.

Code:
Sub PWSub()
    If (Now() - Int(Now()) < TimeValue("6:30:00")) Then
        MsgBox "You are attempting to pull the data too early.  Data is not available until after 6:30"
        ElseIf (Now() - Int(Now()) > TimeValue("19:30:00")) Then
        MsgBox "Data needs to be pulled before 11:00 AM daily. Try again tomorrow"
    Else
        OpenPrevWeek
    End If
End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Code:
Sub PWSub2()
    If LCase(Sheets("Home").Range("G9").Text) = "select" Then
        MsgBox "Procedure will now terminate."
        Exit Sub
    ElseIf Sheets("Home").Range("G9") <> "" Then
        If (Now() - Int(Now()) < TimeValue("6:30:00")) Then
            MsgBox "You are attempting to pull the data too early.  Data is not available until after 6:30"
        ElseIf (Now() - Int(Now()) > TimeValue("19:30:00")) Then
            MsgBox "Data needs to be pulled before 11:00 AM daily. Try again tomorrow"
        Else
            OpenPrevWeek
        End If
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top