+ Reply to Thread
Results 1 to 6 of 6

Having trouble with "If, Then, Else" statement

  1. #1
    Forum Contributor
    Join Date
    09-06-2012
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    225

    Post Having trouble with "If, Then, Else" statement

    Hello,

    I have an example of something i am trying to complete, but keep getting an error.

    The "If, Then" part of the statement works, but when I add the "Else" statement, it gives me a compile error- "Else without If." I do not understand this because I have an "If" prior to the "Else". Please assist.

    *Reminder: This is just a practice example for me to understand how to code an If, Then, Else statement.


    Please Login or Register  to view this content.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Having trouble with "If, Then, Else" statement

    Gard5096,

    When you have the Then statement on the same line as the If statement, the VBA compiler considers that a complete statement. You'll need to either move the Else up to be on the same line...
    Please Login or Register  to view this content.


    Or split everything out into its separate lines....
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Having trouble with "If, Then, Else" statement

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    09-06-2012
    Location
    New York
    MS-Off Ver
    Excel 2007
    Posts
    225

    Re: Having trouble with "If, Then, Else" statement

    You guys are both right, thank you very much! I didnt realize they had to be on seperate lines.

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Having trouble with "If, Then, Else" statement

    My code was a duplicate of Tiger's code. I would not have posted it had I saw Tiger's code. I think there is terrible slow screen updating on this site. I see there is not posting and when I post a reply, there is already a reply.

  6. #6
    Registered User
    Join Date
    11-26-2012
    Location
    Kitchener, Ontario, Canada
    MS-Off Ver
    Excel 2010
    Posts
    82

    Re: Having trouble with "If, Then, Else" statement

    >>> If satisfied with a solution, don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Last edited by aelgadi; 12-05-2012 at 02:10 PM.
    aelgadi

    > Click Star if I helped. Thanks

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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