Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Proper way to add an "or" expression in VBA

Posted on 2011-09-07
6
Medium Priority
?
273 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 2000 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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

916 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