+ Reply to Thread
Results 1 to 8 of 8

If condition is met Then End If Else results in Else without If error

  1. #1
    Registered User
    Join Date
    06-13-2014
    Posts
    23

    If condition is met Then End If Else results in Else without If error

    Hello all,
    I have an issue that I am sure is an easy solve. But I am a little stumped. The code below is supposed to format the selected range, however, since I am using End(xlDown) if there are no values in that range it will select the entire sheet. Since a give range will never be more than a few hundred, so if it selects more than 1000 rows, I want it to skip the formatting. My guess is that I have the syntax wrong for ending the If when the >1000 condition is met. This is part of the code that is telling me "Else without If":

    Please Login or Register  to view this content.
    Thanks

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: If condition is met Then End If Else results in Else without If error

    Remove the first End If.
    If posting code please use code tags, see here.

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

    Re: If condition is met Then End If Else results in Else without If error

    What is RowTotSub(1)? Seems to be wrong

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    06-13-2014
    Posts
    23

    Re: If condition is met Then End If Else results in Else without If error

    Norrie,
    If I remove the first end if then it just goes to the else and I am back to the original problem which is that it selects the entire sheet. I need a way to exit or end the if if the condition is met.
    AB33,
    RowTotSub(1 To 4) is a Variant.

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

    Re: If condition is met Then End If Else results in Else without If error

    If it true, the code is not doing anything, hence I added a line with a comment.

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: If condition is met Then End If Else results in Else without If error

    Hi, edopts,

    why not reverse the comparision?
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: If condition is met Then End If Else results in Else without If error

    The code will only goto the Else part if the condition in the If is not true.

    ie if there are less than, or uqual to, 1000 rows then the code will go to the Else part.

    PS The code you posted doesn't actually select anything.

  8. #8
    Registered User
    Join Date
    06-13-2014
    Posts
    23

    Re: If condition is met Then End If Else results in Else without If error

    HaHoBe,
    That worked! Thanks!

    Norie,
    I omitted the selection part because that worked and would have required posting far more code to make the selection process understandable. It was the formatting part I was having trouble with.

+ 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. Pulling a string of results from a single condition
    By ScottBeatty in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-07-2014, 06:25 PM
  2. [SOLVED] Countifs based on two condition and display results only one time
    By kkharis in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 11-16-2013, 05:56 AM
  3. Replies: 3
    Last Post: 05-26-2012, 08:02 AM
  4. Replies: 5
    Last Post: 05-16-2012, 01:47 PM
  5. Different results depending on condition
    By bronkista in forum Excel General
    Replies: 1
    Last Post: 07-11-2011, 12:12 PM

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