Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBA Code

Posted on 2011-09-03
5
Medium Priority
?
223 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 35

Accepted Solution

by:
Norie earned 2000 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 35

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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

604 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