Results 1 to 3 of 3

Thread: How do I get .Range to recognize a string value?

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2016
    Location
    Cary, NC
    Posts
    2

    How do I get .Range to recognize a string value?

    I have the following code:

    Code:
    If .Range("A" & RowCount) = .Range("A" & (RowCount - 1)) _
    And .Range("B" & RowCount) = .Range("B" & (RowCount - 1)) _
    And .Range("C" & RowCount) = .Range("C" & (RowCount - 1)) _
    And .Range("E" & RowCount) = .Range("E" & (RowCount - 1)) _
    Or .Range("E" & RowCount) = ("Discount" Or "Gratuity" Or "Tax") Then
    I'm having trouble with the Or statement on the last line. What I'm trying to ask on lines 4 and 5 is: (if RowCount = 2) if E2 is equal to E1 Or if E2 is equal to "Discount", "Gratuity", or "Tax". I looked up the .Cell property but that doesn't seem to work either. What's the best way to accomplish this?
    Last edited by bishoposiris; Oct 17th, 2017 at 07:55 AM. Reason: Answered

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: How do I get .Range to recognize a string value?

    This looks like VBA, in which case I can move it to the right forum. However, the Or statement on the last line has trouble in any language. While it would be nice to make it as compact as you have, it simply isn't possible. What you are doing is ORing together the three strings, then comparing that to the range ("E" & RowCount). ORing together three strings, will result in True (or it will crash, which would probably be better, since there's no way that True is the expected result).

    You'd have to write it out:

    (.Range("E" & RowCount) = "Discount" OR .Range("E" & RowCount) = "Gratuity" OR .Range("E" & RowCount) = "Tax")
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2016
    Location
    Cary, NC
    Posts
    2

    Re: How do I get .Range to recognize a string value?

    This worked. Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width