• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 224
  • Last Modified:

VBA Code

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
0
sandramac
Asked:
sandramac
  • 2
  • 2
1 Solution
 
NorieData ProcessorCommented:
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.
0
 
byundtCommented:
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.
0
 
NorieData ProcessorCommented:
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.
0
 
sandramacAuthor Commented:
Thanks, it worked perfectly.
0
 
byundtCommented:
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now