IF, AND, OR within a statement to launch a pop up message

Beatrice

Board Regular
Joined
Sep 17, 2019
Messages
85
Office Version
  1. 2019
Platform
  1. Windows
Here is my logic, which works fine in the excel formula:
=IF(AND(OR(C3<>"x",C4<>"x"),C6="HK"),"error","ok")

but how about turn it to VBA?

My trial:
VBA Code:
Sub CheckConflict()
If Range("C3") <> "x" Or Range("C4") <> "x" Then
If Range("C6") = "HK" Then
MsgBox "Are you sure to proceed?", vbYesNo + vbExclamation, "Conflict Found"
End If
End Sub

it alarms me for error but I am not sure how to fix it.
could anyone please help me?
Thanks a lot in advance.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
You need another End If....

VBA Code:
Sub CheckConflict()
    If Range("C3") <> "x" Or Range("C4") <> "x" Then
        If Range("C6") = "HK" Then
            MsgBox "Are you sure to proceed?", vbYesNo + vbExclamation, "Conflict Found"
        End If
    End If
End Sub
 
Upvote 0
Ooops ! it should be obvious to see :P
Thank you for your help.
Have a good day.
 
Upvote 0
You're welcome but just a couple of things..
Ooops ! it should be obvious to see :P
It is a lot easier to see errors like this one if you indent your code like I have done in my reply (you can do it manually, there are various bits of VBA on the net to do it or I use a free program called Rubberduck).

Also if you encounter an error then you should state in the post what the error states, it didn't make any difference in this thread as it was easy to spot the issue but most of the time it saves us guessing or asking.

You have a good day as well :)
 
Upvote 0

Forum statistics

Threads
1,213,497
Messages
6,113,998
Members
448,541
Latest member
iparraguirre89

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