VBA Code

sandramac
sandramac used Ask the Experts™
on
Hello all, got another portion of my code that i cant quite get. X46="" and x47="", but it still places the "X", which in this case it should just end it evaluation and move on.

Set rFind = Sheets("Sheet13").Cells.Find(StrData2, LookIn:=xlValues, LookAt:=xlWhole)
    If WS.Range("X46").Value And WS.Range("X47").Value <> "" Then
        Sheets("Sheet13").Cells(rFind.Row, "I") = "X"
        Else
    End If
    Set rFind = Nothing
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Analyst Assistant
Commented:
The logical expression isn't quite right.
If (WS.Range("X46").Value <> "") And (WS.Range("X47").Value <> "") Then

Open in new window

You might not need the extra parentheses, but they help clarify the arguments.
byundtMechanical Engineer
Most Valuable Expert 2013
Top Expert 2013

Commented:
imnorie is correct. The way you were testing the two cells, you first get a 0 for the concatenation and then compare that to an empty string.
NorieAnalyst Assistant

Commented:
byundt

Not sure it's concatenation, if you mean the And that is.

When you use And like that some sort of logical operation takes place.

I think it might be bitwise.

Author

Commented:
Thanks, it worked perfectly.
byundtMechanical Engineer
Most Valuable Expert 2013
Top Expert 2013

Commented:
I misspoke.

With two blank cells, the following statement returns 0 in the Immediate pane:
Set WS = ActiveSheet : ?WS.Range("X46").Value And WS.Range("X47").Value <> ""       'Returns 0

Whereas, doing it your way works:
Set WS = ActiveSheet : ?WS.Range("X46").Value <>"" And WS.Range("X47").Value <> ""       'Returns False

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial