+ Reply to Thread
Results 1 to 7 of 7

Basic VBA If Else confusion

  1. #1
    Forum Contributor
    Join Date
    01-18-2013
    Location
    England
    MS-Off Ver
    2016 (Mac)
    Posts
    149

    Smile Basic VBA If Else confusion

    Hello world,

    So below is my attempt at an If else statement but needless to say 1. It is not working and 2. My VBA needs some help!
    I have tried other ways to get this to work but keep on getting error messages. I know that it is a bit of a mess but my VBA is just not that strong. I think it can be done all in one with the correct arrangement of else if's but I may be wrong?

    Would anyone mind re-arranging it or guiding me in order to get it working:


    Please Login or Register  to view this content.
    Thank you in advance for any help

  2. #2
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Basic VBA If Else confusion

    Quote Originally Posted by Margate View Post
    I think it can be done
    What can be done? You never stated what the purpose of the code was, only that its not working. Itd be like giving someone bad instructions for building a mystery device and then asking them how it should actually be done. We cant say because we can only try and guess at what you want to do based on the code you gave us which doesn't work and has no context (we have no sample file to see what its looking at or why).
    Ways to get help: Post clear questions, explain your overall goal, supply as much background as possible, respond to questions asked of you by those trying to help and post sample(s) files.

    "I am here to help, not do it for people" -Me

  3. #3
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,827

    Re: Basic VBA If Else confusion

    What do you mean that it does not work? I get no error messages and it seems to work just fine in a new, blank workbook (well, I have to put something into K69 and a few cells below to see it work).

    I note that all Range() objects are unqualified (nothing in front), which means they will refer to the active worksheet. Is it possible that some of your errors are because you need this to act on something other than the active worksheet? In any case, I could see value in qualifying every range object [Thisworkbook.worksheets(1).range(...)] just so there is not ambiguity. But that should not be necessary to make the procedures run as is.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  4. #4
    Forum Contributor
    Join Date
    01-18-2013
    Location
    England
    MS-Off Ver
    2016 (Mac)
    Posts
    149

    Re: Basic VBA If Else confusion

    Apologies, I have added a spreadsheet. The code is part of a far bigger macro and this is just a section of it. When I run it I am met with the following error message:

    Compile Error
    Expected End Sub
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    01-18-2013
    Location
    England
    MS-Off Ver
    2016 (Mac)
    Posts
    149

    Re: Basic VBA If Else confusion

    In my spreadsheet, there I need to sort the comments and bring them to the top of the list. If there is no comments then both the Job # and comment sections need to be deleted. If there is just one comment then everything below that comment needs to be deleted. Ultimately I can only end up with a maximum of 2 comments.

    Hope this makes sense.

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,827

    Re: Basic VBA If Else confusion

    As written, you have two End Sub statements at the end of the module, and no End Sub statements before Sub emptycell(). If you put an End Sub before Sub emptycell(), so that VBA can correctly see that you have two Sub procedures, and get rid of the extra End Sub at the bottom, then it should compile. From there, it looks like it might work with no additional modification.
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    01-18-2013
    Location
    England
    MS-Off Ver
    2016 (Mac)
    Posts
    149

    Re: Basic VBA If Else confusion

    Brilliant. That works perfectly, thank you very much for your time and help. I will mark this thread as solved.

    Regards,

    Margate

+ 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. [SOLVED] =SUM Confusion
    By CynideHigh in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 11-12-2017, 02:41 PM
  2. import XML confusion
    By Trachr in forum Excel General
    Replies: 0
    Last Post: 08-21-2015, 08:36 PM
  3. [SOLVED] If, And, Or Confusion!
    By amyindubai in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 04-10-2012, 04:12 PM
  4. Confusion with last row
    By LiLi1 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-15-2011, 06:09 PM
  5. Else If Confusion in VBA
    By SAsplin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-27-2011, 10:06 AM
  6. Confusion.....
    By Eric @ CMN, Evansville in forum Excel General
    Replies: 3
    Last Post: 12-27-2005, 03:20 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