Solved

Proper way to add an "or" expression in VBA

Posted on 2011-09-07
6
242 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:Ingeborg Hawighorst
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

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.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
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 demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

777 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