Worksheet_SelectionChange MsgBox IF/THEN Statment

hubhockey

New Member
Joined
Jun 8, 2011
Messages
4
What I am looking to do with this code is I want to look at cells B4:I38 and first see if they have been locked, if so than when a user selects a cell within that range the below message box (in the code) appears. But if the user selects a cell outside of that range than no message appears.

So the first half of this code works, however when the user clicks on a cell outside of the range I get an "Object variable or with block variable not set" run error message. Any help?


Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 
    If Range("B4:I38").Locked = True And Not Intersect(Target, Range("B4:I38")) Then
       MsgBox "Day closed! Requests & adjustments must be emailed to the Workforce Management Team for approval. Thank you!"
    Else
       'Do nothing
End If
End Sub
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
 
    If Not Intersect(Target, Range("B4:I38")) Is Nothing Then
        If Target.Locked Then MsgBox "Day closed! " & vbCr & _
           "Requests & adjustments must be emailed to the Workforce Management Team for approval. " _
            & vbCr & vbCr & "Thank you!"
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,693
Members
449,117
Latest member
Aaagu

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