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

Proper way to add an "or" expression in VBA

Posted on 2011-09-07
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)
Question by:angelfromabove
  • 2
  • 2

Accepted Solution

slycoder earned 500 total points
ID: 36497676

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

Author Comment

ID: 36497747
Thank you, do I need the underscores? and do I also need a comma before Then?

Expert Comment

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.


Author Comment

ID: 36498034
Got it thank you very much, it worked!
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.

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

791 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