Check cell for two sets of data

aaronz07

New Member
Joined
Feb 13, 2007
Messages
25
Hi All,

I have a column that can contain two values each cell can contain one value at a time

Eg.

Apple
Cherry
Apple
Cherry

The whole column is filled with either values and nothing else. I used a macro of if statements to check the cell data is Apple OR Cherry if it contains something else it will use msgbox to display that error found and it's not Apple or Cheery but it keeps getting wrong info.

If cells(i, 1).value <> “Apple” Or cells(i, 1).value <> “Cherry” then
Msgbox ”error”
End if
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
The whole column is filled with either values and nothing else. I used a macro of if statements to check the cell data is Apple OR Cherry if it contains something else it will use msgbox to display that error found and it's not Apple or Cheery but it keeps getting wrong info.

If cells(i, 1).value <> “Apple” Or cells(i, 1).value <> “Cherry” then
Msgbox ”error”
End if
Try changing that Or to And
 
Upvote 0
Thanks
I did that it marked every cell as an error but I did this seems to work what's your thought.

If cells(i, 1).value <> “Apple” Or cells(i, 1).value <> “Cherry” then

' do nothing
Else
Msgbox ”error”
End if
 
Upvote 0
1. Make sure you are using these quote marks " not these “ and these ”

2. After you fix the quote marks, the code in post 3 will never get to the MsgBox because one (or both) of the red or the blue conditions below will always be true.
So the "Do nothing" will always occur.

If Cells(i, 1).Value <> "Apple" Or Cells(i, 1).Value <> "Cherry" Then


Perhaps I am not understanding what you are trying to do. If you still need help please post ..

- a small set of sample data that contains a range of possibilities for values in column A (not just Apple and Cherry).
- clearly explain what you want to happen for each of those values.
- post the full code that you are using and explain where it is going wrong.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
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