How to make Warning message depend on two cells.

DemonX

New Member
Joined
Jan 17, 2021
Messages
20
Office Version
  1. 2019
Platform
  1. Windows
I want to generate a warning message when a value is added to E6 cell , when there is already value at E5 cell.

Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Application.Intersect(Range("E5", "E6"), Target) Is Nothing) Then
MsgBox "Do not use both", vbInformation, "Kutools for Excel"
End If
End Sub

I used above and I could not wrap my head around to make this work :(. Further, it would be so great if E6 raw could be highlighted from red when there is value in E5 and when another value is add in E6 too.

Any assistance is highly appreciated
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Try this:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Modified  3/26/2021  12:27:34 PM  EDT
If Target.Cells.CountLarge > 1 Or IsEmpty(Target) Then Exit Sub

If Target.Address = Range("E6").Address Then
    Target.Interior.Color = xlNone
    If Target.Offset(-1).Value <> "" Then
    Target.Interior.Color = vbRed
        MsgBox "Do Not Use Both" & vbNewLine & "Range(""E5"") already has a value", vbInformation
    End If
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,585
Members
448,972
Latest member
Shantanu2024

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