+ Reply to Thread
Results 1 to 7 of 7

syntax for If/Else/End If

  1. #1
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    syntax for If/Else/End If

    Keep getting Else Without If errors... someone help me with the proper syntax for my code:

    Please Login or Register  to view this content.

    Please and thank you!!
    Last edited by HeyInKy; 10-15-2014 at 04:00 PM.

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

    Re: syntax for If/Else/End If

    I am not sure why you have and after then, but this will get rid of the error, though it might not be correct

    Please Login or Register  to view this content.

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,021

    Re: syntax for If/Else/End If

    When you put the a statement after the Then on the same line,the whole line stands alone as a single statement. It is not part of an If/End If structure. To fix that, move the statement after the Then onto the next line.

    Because you are checking chk to be either True or False your logic can be further simplified to

    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,581

    Re: syntax for If/Else/End If

    Please Login or Register  to view this content.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    27,021

    Re: syntax for If/Else/End If

    Upon reading AB33's post I realized that you almost certainly have another error.

    Please Login or Register  to view this content.
    This is syntactically legal but I am 99.9% sure it's not what you intend.

    I suspect you really want to do two separate things:

    Please Login or Register  to view this content.
    The And is logical operator. It does not mean "do this And do that".

  6. #6
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Re: syntax for If/Else/End If

    Yes - thanks to all - I realized I do not need the AND operator...

    and actually, playing with the provided suggestions, I have two sub routines that appear (at first testing) to accomplish what I need without using ELSE and/or END if...

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    Thanks again!

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,581

    Re: syntax for If/Else/End If

    You're welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. syntax???
    By hvisa in forum Excel General
    Replies: 0
    Last Post: 04-11-2007, 09:14 AM
  2. 'If' syntax
    By hvisa in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 01-30-2007, 04:33 PM
  3. help with syntax
    By anny in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2006, 10:10 PM
  4. Syntax help please
    By GettingThere in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-18-2005, 09:05 PM
  5. Syntax Help
    By Dmorri254 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-02-2005, 11:06 AM

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