+ Reply to Thread
Results 1 to 6 of 6

Block If without End If

  1. #1
    Registered User
    Join Date
    10-12-2010
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    3

    Unhappy Block If without End If

    When I try to run the following VBA code, I get a Block If without End If error. I can't figure out where I need to add the End If or if more than one is needed.

    Please Login or Register  to view this content.
    Last edited by dannykeith; 10-12-2010 at 10:32 AM. Reason: Add code tags

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Block If without End If

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Block If without End If

    If you indent your code, you'll see you have many unclosed block Ifs:

    Please Login or Register  to view this content.
    The indenting should come all the way back to the left.
    Last edited by shg; 10-12-2010 at 10:35 AM. Reason: waiting for OP
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    10-12-2010
    Location
    United States
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Block If without End If

    When I used the code I got the same error message.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Block If without End If

    Your code is unchanged other than indenting it just to make the problem visually apparent, Danny. I can't make a suggestion because I don't know the logic you're trying to implement -- but you can see that your code is getting more deply nested without unwinding.

  6. #6
    Registered User
    Join Date
    08-01-2010
    Location
    American in Rovereto, Italy
    MS-Off Ver
    Excel 2010 home & Excel 2010 work
    Posts
    46

    Re: Block If without End If

    You might benefit by changing your approach, just switch from deeply nested IF structure to a simpler Select case Structure
    like so.

    Please Login or Register  to view this content.
    Another way to help clear up your code is to factor out the repeating stuff. Your code constantly repeats range locations. You could try adding something like this to you code. It will make it much easier to read too.
    Please Login or Register  to view this content.
    Gordon in Rovereto, Italy

+ 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