Testing for user entered errors in cells

dunk123

Board Regular
Joined
Feb 14, 2008
Messages
77
This used to work fine in Excel 2003, but I've just noticed that using Excel 2007 it doesn't seem to be performing in the same way. I have a range of cells in a column, and this code loops through the range to test if the user has left it blank or put in some data that is deemed to be incorrect from the list contained within the IF statement below, and if it does meet the criteria then the cell is coloured yellow and it moves on the the next one. What it is now doing is finding that every cell meets the criteria and colouring it yellow. For example, I've just witnessed sCellCheck = "BENNI X" or "TINE MUNK" and the cell has been coloured. Anyone able to advise why it would do that? Thanks all.

Code:
For Each sCellCheck In sRange
        If sCellCheck Like "" Or sCellCheck Like "*?*" Or LCase(sCellCheck) Like "x x" Or sCellCheck Like "- -" Or sCellCheck Like "-- --" Or sCellCheck Like "*--*" Or sCellCheck Like "- --" Or sCellCheck Like "- - -" Or sCellCheck Like "- - --" Or sCellCheck Like "-- -- --" Or sCellCheck Like "-- - --" Or sCellCheck Like "-- ---" Then
            sCellCheck.Select
            With Selection.Interior
                .Color = 65535
            End With
        End If
    Next
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Code:
sCellCheck Like "*?*"

I think this line is a problem it will include every string more then 3 I guess
</pre>
 
Upvote 0
Thanks. I just removed the * from that and you are right. How can I then test for a question mark within the cell anywhere, which is what that section was trying to do?
 
Upvote 0
Remember Even '?' represents any single letter string. If you want to know wheather a cell has ? then use '~?'.
 
Upvote 0
I tried:

Code:
If sCellCheck Like "" Or sCellCheck Like "~?"

but this doesn't pick it up when the value in the cell is "LOTTE .?" or "GABI O?TT"
 
Upvote 0
So now we have
Code:
If sCellCheck Like "" Or sCellCheck Like "*~?*"
and it does not pick up "JEPPE HIRSCH?" but does pick up "LEIF OLSEN~?"

Should I perhaps be using the character USCII number instead to test for a question mark? How would this be done to include the wildcards?
 
Upvote 0
My Bad, I got a bit confused between excel and VBA my above code is useful for Excel and for VBA this would help:

Code:
"*[?]*"
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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