Solved

VBA Code

Posted on 2011-09-03
5
212 Views
Last Modified: 2012-05-12
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
Comment
Question by:sandramac
  • 2
  • 2
5 Comments
 
LVL 33

Accepted Solution

by:
Norie earned 500 total points
ID: 36479304
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
 
LVL 81

Expert Comment

by:byundt
ID: 36479310
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
 
LVL 33

Expert Comment

by:Norie
ID: 36479316
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
 

Author Closing Comment

by:sandramac
ID: 36479338
Thanks, it worked perfectly.
0
 
LVL 81

Expert Comment

by:byundt
ID: 36479353
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now