Results 1 to 5 of 5
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    La Jolla, CA
    Posts
    1,479
    Thanks
    31
    Thanked 63 Times in 59 Posts

    VBA formula needs quotes

    This is driving me crazy (crazier than I am already),

    I need to test within VBA, but these quotes that need to be around the text HOL and VAC have me totally stumped. As written below, it doesn't work.

    Range("K2:K100").Formula = "=IF(OR(B2="HOL",B2="VAC"),B2,E2)"

    TIA

  2. #2
    Super Moderator RetiredGeek's Avatar
    Join Date
    Mar 2004
    Location
    Manning, South Carolina
    Posts
    9,483
    Thanks
    376
    Thanked 1,471 Times in 1,339 Posts
    Quote Originally Posted by kweaver View Post
    This is driving me crazy (crazier than I am already),

    I need to test within VBA, but these quotes that need to be around the text HOL and VAC have me totally stumped. As written below, it doesn't work.

    Range("K2:K100").Formula = "=IF(OR(B2=" & Chr(32) & "HOL" & chr(32) & ",B2=" & chr(32) & "VAC" & chr(32) & "),B2,E2)"

    TIA
    Kevin, Here's the way I prefer to do it. See above. I hope I got it right as I'm typing this on a Kindle Fire from a hospital bed at 2:20AM! Just had a bionic, don't I wish, left knee installed yesterday morning and it looks like they will let me out before lunch if I can navigate stairs in the morning.

    HTH
    Last edited by RetiredGeek; 2016-10-18 at 02:26.
    May the Forces of good computing be with you!

    RG

    PowerShell & VBA Rule!

    My Systems: Desktop Specs
    Laptop Specs

  3. #3
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,284
    Thanks
    3
    Thanked 193 Times in 179 Posts
    You can also just double any quotes inside the formula string:

    Code:
    Range("K2:K100").Formula = "=IF(OR(B2=""HOL"",B2=""VAC""),B2,E2)"
    Regards,
    Rory

    Microsoft MVP - Excel

  4. #4
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    La Jolla, CA
    Posts
    1,479
    Thanks
    31
    Thanked 63 Times in 59 Posts
    WOW. RG...hope all turns out ok. You're definitely the new super-hero now!

  5. #5
    WS Lounge VIP
    Join Date
    Mar 2002
    Location
    Newcazzle, UK
    Posts
    2,941
    Thanks
    140
    Thanked 512 Times in 488 Posts
    Hi

    Hope you recover soon RG.
    Remember, laughter isn't the best medicine. Morphine is.

    zeddy

  6. The Following User Says Thank You to zeddy For This Useful Post:

    rory (2016-10-18)

Posting Permissions

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