+ Reply to Thread
Results 1 to 5 of 5

Simplify numerous conditional statements

  1. #1
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Manila, Philippines
    MS-Off Ver
    2019
    Posts
    102

    Simplify numerous conditional statements

    Hello Excel champions!

    While the block of code below works however, it looks quiet an eye-sore as there are so many iterations that I believe can be simplified with nested loops. While I am currently fighting my intimidation to Looping statements, can you guys shed a light on me as to how this can be reduced into its simplest form? I will be going to study your solutions and hopefully get past my fear in looping.

    Thanks in advance.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,942

    Re: Simplify numerous conditional statements

    If it works, it's good. The code logic could be simplified by redesigning your input, say, by disabling controls when certain entries are made, or limiting the values allowed. But that would require other code. Or you could simplify it when all you are checking is that the angle(?) values are less than 90 or blank, like this, though this may miss other requirements:

    If (.TextBox6.Value <= 90 Or .TextBox6.Value = "") And _
    (.TextBox7.Value <= 90 Or .TextBox7.Value = "") And _
    (.TextBox8.Value <= 90 Or .TextBox8.Value = "") And _
    (.TextBox9.Value <= 90 Or .TextBox9.Value = "") And _
    (.TextBox12.Value <= 90 Or .TextBox12.Value = "") Then
    Call sb_tube_less_equal_90
    GoTo Drawing
    Exit Sub
    Else
    GoTo Errmessage
    Exit Sub
    End If
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Manila, Philippines
    MS-Off Ver
    2019
    Posts
    102

    Re: Simplify numerous conditional statements

    Quote Originally Posted by Bernie Deitrick View Post
    If it works, it's good. The code logic could be simplified by redesigning your input, say, by disabling controls when certain entries are made, or limiting the values allowed. But that would require other code. Or you could simplify it when all you are checking is that the angle(?) values are less than 90 or blank, like this, though this may miss other requirements:

    If (.TextBox6.Value <= 90 Or .TextBox6.Value = "") And _
    (.TextBox7.Value <= 90 Or .TextBox7.Value = "") And _
    (.TextBox8.Value <= 90 Or .TextBox8.Value = "") And _
    (.TextBox9.Value <= 90 Or .TextBox9.Value = "") And _
    (.TextBox12.Value <= 90 Or .TextBox12.Value = "") Then
    Call sb_tube_less_equal_90
    GoTo Drawing
    Exit Sub
    Else
    GoTo Errmessage
    Exit Sub
    End If
    Your suggestion of disabling the remaining controls if some controls do not meet criteria seems logical and will definitely consider that approach, thank you for that. Your AND-OR combination might do the trick but still has the length issues I am trying to resolve.

    Yes, the code is working and does its purpose, but my OC side of me is itching and wants to know if there are other ways to simplify it. Plus, I do not want other coders who will work on it to get lost in the process should they need to make some adjustment, in case I am not around to do it.
    Last edited by ykobure; 09-04-2015 at 04:53 AM.

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Simplify numerous conditional statements

    Quote Originally Posted by ykobure View Post
    Plus, I do not want other coders who will work on it to get lost in the process should they need to make some adjustment, in case I am not around to do it.
    I'd suggest you start by giving your controls more meaningful names then - currently anyone new will have to keep referring to the form to remind themselves what each control actually is.
    Remember what the dormouse said
    Feed your head

  5. #5
    Forum Contributor
    Join Date
    08-29-2012
    Location
    Manila, Philippines
    MS-Off Ver
    2019
    Posts
    102

    Re: Simplify numerous conditional statements

    Quote Originally Posted by romperstomper View Post
    I'd suggest you start by giving your controls more meaningful names then - currently anyone new will have to keep referring to the form to remind themselves what each control actually is.
    I actually practice the proper naming convention when dealing with my controls in userform in larger projects. This project however is a small one and only has one userform, hence the use of default names. But I will keep that suggestion of yours in my future projects. Thanks Rory.

    I would appreciate other inputs from you experts

+ 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] Shortcut for numerous conditional formatting rules?
    By Butcher1 in forum Excel General
    Replies: 2
    Last Post: 11-24-2014, 01:01 PM
  2. VBA Conditional formatting (Less than / Greater than) for numerous ranges
    By Ramzess in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 08-05-2013, 05:59 PM
  3. Simplify and Combine Complicated Conditional Formula
    By amyxkatexx in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-13-2010, 02:51 PM
  4. Conditional statements
    By gigaworks in forum Excel General
    Replies: 1
    Last Post: 01-26-2010, 07:37 PM
  5. Conditional statements using IF
    By ibabs in forum Excel General
    Replies: 4
    Last Post: 12-22-2009, 06:57 PM
  6. how to use conditional statements
    By maverick3483 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-07-2009, 07:06 AM
  7. IF conditional statements
    By Alex Martinez in forum Excel General
    Replies: 2
    Last Post: 08-22-2005, 03: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