Solved

VBA Code

Posted on 2011-09-03
5
213 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

813 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

13 Experts available now in Live!

Get 1:1 Help Now