Create error messages based on entries in 2 cells

dori2o

Board Regular
Joined
Apr 7, 2016
Messages
72
I have a sheet which calculates charges due on an account.


I have a box at B10 which can be completed to offer a discount.


I have a dropdown which references to box D5 where a user can select a 'Loyalty Discount' (shows "1" for no discount, then either "2"or "3" for the level of discount.


The customer cannot have both, therefore I am looking for a vba (unless this can be done in validation) code that will trigger if an entry is entered into B10 and the loyalty discount is already given at D5. Or where the loyalty discount is selected from the dropdown and and entry already exists at B10.

Unfortunately I cannot provide an example of the sheet as it contains confidential information.


As always your help is greatly appreciated.


Thanks
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I'm not sure if I understood correctly but try this macro in the worksheet code module:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("B10,D5")) Is Nothing Then Exit Sub
    Application.EnableEvents = False
    Select Case Target.Address
        Case "$B$10"
            If Range("D5") <> "" Then
                MsgBox ("Loyalty Discount already exists in cell D5.")
                Target.ClearContents
                Application.EnableEvents = True
                Exit Sub
            End If
        Case "$D$5"
            If Range("B10") <> "" Then
                MsgBox ("Discount already exists in cell B10.")
                Target.ClearContents
                Application.EnableEvents = True
                Exit Sub
            End If
    End Select
    Application.EnableEvents = True
End Sub
 
Upvote 0
I'm not sure if I understood correctly but try this macro in the worksheet code module:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("B10,D5")) Is Nothing Then Exit Sub
    Application.EnableEvents = False
    Select Case Target.Address
        Case "$B$10"
            If Range("D5") <> "" Then
                MsgBox ("Loyalty Discount already exists in cell D5.")
                Target.ClearContents
                Application.EnableEvents = True
                Exit Sub
            End If
        Case "$D$5"
            If Range("B10") <> "" Then
                MsgBox ("Discount already exists in cell B10.")
                Target.ClearContents
                Application.EnableEvents = True
                Exit Sub
            End If
    End Select
    Application.EnableEvents = True
End Sub


Thanks.

Unfortunately I've just tried it and it fires whenever any entry is made in B10

It also doesn't fire when D5 is changed by selecting the dropdown options.

I've been trying different options such as using a helper column, with an IF/AND statement in F1 as follows:

=IF(AND(B10>0,D5>1),TRUE,FALSE)

The formula works but I'm now struggling to understand how to get data validation/macro to fire when the
cell changes to True
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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