Comapre two cells and display the results accordingly

Karthikeyan Devan

Board Regular
Joined
May 5, 2009
Messages
114
Hi All,

I need a VBA code where it check the criterias and display the result.

Suppose if A1 states "Hi" and B2 states "Hello" in cell C2 automatically display the result stating "Don't assign".

iF A2 states "Hello" and B2 states "Hey" then in cell C2 automatically display "Please assign".

To be more clear, A2 and B2 has a filter option where users choose from dropdown. According to the criteria, it has to display the result in C2, wherein C2 is also have a filter option where it has two options to display. One is Please assign and Don't assign.

Please assist me on this. Also, whatever it displays in C2 has to come has a Msg box as well which make people more alert.

Thank you for looking into this.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Code:
Sub test()

If Sheet1.Range("A1").Value = "Hi" And Sheet1.Range("B2").Value = "Hello" Then
     Sheet1.Range("C2").Value = "Don't assign"
ElseIf Sheet1.Range("A2").Value = "Hello" And Sheet1.Range("B2").Value = "Hey" Then
     Sheet1.Range("C2").Value = "Please assign"
End If

End Sub

Replace Sheet1 with a code name for your worksheet, if needed.
 
Upvote 0
To be more clear, A2 and B2 has a filter option where users choose from dropdown. According to the criteria, it has to display the result in C2, wherein C2 is also have a filter option where it has two options to display. One is Please assign and Don't assign.

So how does A1 fit into this?

Suppose if A1 states "Hi" and B2 states "Hello"
 
Upvote 0
Hi All,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
Thank you for getting back on this. Sorry for the confusion first of all. There are many criteria’s like this. Only if it is two we can use the Else if statement but I have many.<o:p></o:p>
<o:p> </o:p>
Examples are listed down. I believe we need to use nested if but I am not aware of that. Please advice…<o:p></o:p>
<o:p> </o:p>
If A2 states "Hi" and B2 states "Hello" in cell C2 automatically display the result stating "Don't assign".<o:p></o:p>
<o:p> </o:p>
if A2 states "Hey" and B2 states "Hi" in cell C2 automatically display the result stating "Please assign".<o:p></o:p>
<o:p> </o:p>
if A2 states "Rose" and B2 states "Fruit" in cell C2 automatically display the result stating "think before assigning".<o:p></o:p>
<o:p> </o:p>
if A2 states "Yes" and B2 states "No" in cell C2 automatically display the result stating "ignore".<o:p></o:p>
<o:p> </o:p>
Please advice and it would be great help!!!
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,789
Members
452,942
Latest member
VijayNewtoExcel

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