Solved

Proper way to add an "or" expression in VBA

Posted on 2011-09-07
6
221 Views
Last Modified: 2012-05-12
Hello,  Please see the expression below:originally it read as follows:
If Trim(Cell) = "41 Rank" ,Then
            Cell.Offset(0, 57)

However, I'd like to add another variable to the expression so it performs the same actiona if the cell reads "41 Rank" or "42 Rank".  I tried just adding the word "or" as it's written below, but the macro didn't work. I would appreciate any assistance you can offer.

If Trim(Cell) = "41 Rank" or "42 Rank" ,Then
            Cell.Offset(0, 57)
0
Comment
Question by:angelfromabove
  • 2
  • 2
6 Comments
 
LVL 5

Accepted Solution

by:
slycoder earned 500 total points
ID: 36497676
Try:

If Trim(Cell) = "41 Rank" or _
   Trim(Cell) = "42 Rank" Then _
      Cell.Offset(0, 57)
0
 

Author Comment

by:angelfromabove
ID: 36497747
Thank you, do I need the underscores? and do I also need a comma before Then?
0
 
LVL 5

Expert Comment

by:slycoder
ID: 36497940
comma is not needed - the underscores are just "line continuation" characters (preceeding space is required), makes code a little easier to read on multiple lines rather then on a single line.

Thanks
0
 

Author Comment

by:angelfromabove
ID: 36498034
Got it thank you very much, it worked!
0
 
LVL 50

Expert Comment

by:teylyn
ID: 37087206
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
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…

757 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

18 Experts available now in Live!

Get 1:1 Help Now