+ Reply to Thread
Results 1 to 4 of 4

Test in beginning of macro and start from top if false

  1. #1
    Forum Contributor
    Join Date
    01-28-2013
    Location
    sweden
    MS-Off Ver
    Excel 2010
    Posts
    108

    Test in beginning of macro and start from top if false

    Hi,

    I have a inputbox in start of macro where user should enter a number. 5, 10 and 15 are allowed values so I want to test if user have entered any of those

    Please Login or Register  to view this content.
    This is working good enough for me but wonders if this is considered as bad coding? I have heard that GoTo shouldnt be used.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Test in beginning of macro and start from top if false

    Hi,

    Yes there's a school of thought that considers GOTO stuff to be bad coding which can lead to 'spaghetti' code making de-bugging and reading code difficult.

    Presumably to enter your macro the user has to click a button or something so why not just tell them what's wrong and invite them to click again. In which case something like the following is arguably better.
    Please Login or Register  to view this content.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Contributor
    Join Date
    01-28-2013
    Location
    sweden
    MS-Off Ver
    Excel 2010
    Posts
    108

    Re: Test in beginning of macro and start from top if false

    But I would need macro to start from line 1 if user enters wrong value. Macro runs when workbook opens so there is no button to activate macro. Thats why I liked GoTo statement.

    CLng is needed to convert input to integer? 5 would otherwise be considered as a string?

  4. #4
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,926

    Re: Test in beginning of macro and start from top if false

    Try using a while statement;

    Please Login or Register  to view this content.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

+ 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. Logical test false values skip to next row for next test
    By Schecter89 in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-23-2018, 06:36 AM
  2. Replies: 0
    Last Post: 08-11-2015, 05:44 AM
  3. Skip the row if the logical test is false?
    By ridgelyiv in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-23-2011, 03:37 PM
  4. If false, do the logical test for next cell
    By Zvetam in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-21-2008, 07:48 AM
  5. [SOLVED] Macro code to test for blank row and insert blank row if false
    By Mattie in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-28-2006, 08:25 PM
  6. if test using true/false or yes/no
    By toolman in forum Excel General
    Replies: 1
    Last Post: 10-08-2005, 01:05 AM
  7. [SOLVED] how: if, conditional test, true (do nothing if false)
    By jwhitney in forum Excel General
    Replies: 3
    Last Post: 09-13-2005, 11:05 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