Multiple ranges with different xCell.Values for a single MsgBox

dharv3y78

New Member
Joined
Oct 26, 2019
Messages
7
Office Version
  1. 365
Platform
  1. MacOS
Hi MrExcel Forum,
Please Note: this question is also posted in another forum (ExcelForum: Posting here as well as I don't have an answer yet)

I am after a way that will enable a vba code to read one range then another range and if both ranges equal true for corresponding xCell.Value for the particular range then a MsgBox appears.

I want two ranges

First Range - F13:F13 if this range equals "Arthur"
Second Range - B16:B18 if this range equals "Weekday Daytime"

If both of the ranges are meet then I want a MsgBox to say "Please Use Hours Field"

I have the MsgBox showing for one range but can't work out how I might add another range in.

The VBACode I currently have is
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheet4.Unprotect password:=pwd
Application.ScreenUpdating = False
    Dim xCell As Range, Rg As Range
    On Error Resume Next
    Set Rg = Application.Intersect(Target, Range("B16:B18"))
    If Not Rg Is Nothing Then
        For Each xCell In Rg
            If xCell.Value = "Weekday Daytime" Then
                MsgBox "Please Use Hours Field", vbInformation, "Information Regarding Weekday Daytime"
                Exit Sub
            End If
        Next
    End If
    Application.ScreenUpdating = True
Sheet4.Protect password:=pwd
End Sub
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
HTH
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    Sheet4.Unprotect Password:=pwd
    Application.ScreenUpdating = False
    Dim xCell As Range, Rg As Range
    On Error Resume Next
    If Range("F13") = "Arthur" Then
        Set Rg = Application.Intersect(Target, Range("B16:B18"))
        If Not Rg Is Nothing Then
            For Each xCell In Rg
                If xCell.Value = "Weekday Daytime" Then
                    MsgBox "Please Use Hours Field", vbInformation, "Information Regarding Weekday Daytime"
                    Exit Sub
                End If
            Next
        End If
    End If
    Application.ScreenUpdating = True
    Sheet4.Protect Password:=pwd
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,214,812
Messages
6,121,696
Members
449,048
Latest member
81jamesacct

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