+ Reply to Thread
Results 1 to 9 of 9

IF statements + vba

Hybrid View

  1. #1
    Registered User
    Join Date
    12-09-2008
    Location
    Canada
    Posts
    79

    IF statements + vba

    I have code which is the following:
    Range("L2").Value = "IF(ISERROR(Range("K2".Value),"No","Yes")"
    Then I was planning to have it automactially pasted down to the end of the columb, however I keep getting an "Expected: end of statment" error.

    Anyone know how I can bypass this?
    Last edited by GeorgY; 05-07-2009 at 05:59 PM. Reason: solved

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: IF statements + vba

    Looks like you have VBA mixed up with formulas. You don't write a formula like that. Do you mean
    Range("L2").Formula = "IF(ISERROR(K2,"No","Yes")"
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    12-09-2008
    Location
    Canada
    Posts
    79

    Re: IF statements + vba

    hmm I tried that also..same result

    VBA thinks that I should have an "End If" at the end..any other suggestions?

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: IF statements + vba

    Hello GeorgY,

    First, please remember to wrap your code in code tags. (I've done this for you.)

    Second, try changing your code to:
    Range("L2").Formula = "=IF(ISERROR(" & Range("K2").Address & "),""No"",""Yes"")"
    Along Roy's thinking, this too works:
    Range("L2").Formula = "=IF(ISERROR(K2),""No"",""Yes"")"

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: IF statements + vba

    There's a missing =

    Range("L2").Formula = "=IF(ISERROR(K2,"No","Yes")"

  6. #6
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: IF statements + vba

    Roy, your's still doesn't work due to the quotes around No and Yes. You need two sets of quotes for each.

  7. #7
    Registered User
    Join Date
    12-09-2008
    Location
    Canada
    Posts
    79

    Re: IF statements + vba

    thanks guys, both of your codes work! (Roy's when I added a second set of "" though)

    Appreciate it and I'll try to rememeber to wrap code next time

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: IF statements + vba

    This works for me

    Range("L2").Formula = "=IF(ISERROR(K2),""No"",""Yes"")"
    Edit: I spotted the quotes were missing, thanks pjoaquin

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: IF statements + vba

    If you want to fill a range, select the cells then use
    Selection.FormulaR1C1 = "=IF(ISERROR(RC[-1]),""No"",""Yes"")"

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1