+ Reply to Thread
Results 1 to 10 of 10

How not to have to use loats of End If's

  1. #1
    Forum Contributor ndtsteve's Avatar
    Join Date
    05-01-2012
    Location
    Guildford, Surrey, England
    MS-Off Ver
    365 MSO (Version 2310 Build 16.0.16924.20054) 64-bit
    Posts
    104

    How not to have to use loats of End If's

    Every time I add another If command I have to add an End If at the end. Is there a way to avoid this?
    Please Login or Register  to view this content.
    Thanks in advance.......Steve

  2. #2
    Registered User
    Join Date
    04-09-2012
    Location
    São Paulo, Brazil
    MS-Off Ver
    Excel 2007
    Posts
    78

    Re: How not to have to use loats of End If's

    ndtsteve,

    You can use de "ElseIf" in your code.

    Please Login or Register  to view this content.

  3. #3
    Valued Forum Contributor
    Join Date
    02-09-2012
    Location
    Mauritius
    MS-Off Ver
    Excel 2007
    Posts
    1,055

    Re: How not to have to use loats of End If's

    Hi


    Try this:

    Please Login or Register  to view this content.
    Click *, if my suggestion helps you. Have a good day!!

  4. #4
    Forum Contributor
    Join Date
    06-09-2011
    Location
    Germany
    MS-Off Ver
    Excel 2016
    Posts
    194

    Re: How not to have to use loats of End If's

    Hi Steve,

    not sure if the macro really does what you intended. The way how you structured it the second "if" would only be used if the first "if" was already fullfilled. I assume you would like to have it like this instead:
    Please Login or Register  to view this content.
    Regards

    Theo
    Remember To Do the Following....
    1. Upload sample files
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.

  5. #5
    Forum Contributor
    Join Date
    06-09-2011
    Location
    Germany
    MS-Off Ver
    Excel 2016
    Posts
    194

    Re: How not to have to use loats of End If's

    jraj1106 was quicker :-) credits go to him

  6. #6
    Forum Contributor ndtsteve's Avatar
    Join Date
    05-01-2012
    Location
    Guildford, Surrey, England
    MS-Off Ver
    365 MSO (Version 2310 Build 16.0.16924.20054) 64-bit
    Posts
    104

    Re: How not to have to use loats of End If's

    I have tried using ElseIf but if I do that then the subroutine stops after the first MsgBox and does not go thu the rest of them. It runs thru them all if I just use the If's and EndIf's. I am just wondering if there is a 'neater' way to wtite the code.
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    06-09-2011
    Location
    Germany
    MS-Off Ver
    Excel 2016
    Posts
    194

    Re: How not to have to use loats of End If's

    Steve,

    you could do it like this, but it would mean your would activate a new sheet even though the actual issue is not solved.

    Please Login or Register  to view this content.
    Regards

    theo

  8. #8
    Forum Contributor ndtsteve's Avatar
    Join Date
    05-01-2012
    Location
    Guildford, Surrey, England
    MS-Off Ver
    365 MSO (Version 2310 Build 16.0.16924.20054) 64-bit
    Posts
    104

    Re: How not to have to use loats of End If's

    Thanks Fettertiger (theo) that it a great help and now it steps thru the routine

  9. #9
    Registered User
    Join Date
    04-09-2012
    Location
    São Paulo, Brazil
    MS-Off Ver
    Excel 2007
    Posts
    78

    Re: How not to have to use loats of End If's

    ndtsteve,

    Fettertiger is right, your macro should show the error to the user. You can use TextBox instead of MsgBox to user insert the value.

    Pulsus

  10. #10
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: How not to have to use loats of End If's

    Which structure you use depends on the logic needs of your program.

    Please Login or Register  to view this content.

+ 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