+ Reply to Thread
Results 1 to 4 of 4

IF THEN condition

  1. #1
    Registered User
    Join Date
    02-02-2017
    Location
    Caribbean
    MS-Off Ver
    2016
    Posts
    2

    IF THEN condition

    Hello,
    Need assistance please to fix a code below that is not functioning as desired. I have two incremental statements that build on each other and produce a result in cell H9. I would like to stop the iterations if a certain value is reached in cell H9.

    I run the macro but only the statements perform. The If Then statement to stop the macro does not function when it reaches a defined value.

    Could you help me to resolve if I have correctly structured the IF THEN statement based on the incremental results.

    Thanks in advance.

    Sub Iteration_Method()

    If ActiveSheet.Range("H9").Value > 2 Then
    Exit Sub

    End If

    Dim a As Integer

    a = 1

    For a = 1 To 3
    ActiveSheet.Range("D8").Value = a

    Dim c As Integer
    c = 1

    Do
    ActiveSheet.Range("D10").Value = c
    c = c + 1
    Loop Until c > 1000

    Next a

    End Sub

  2. #2
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    Re: IF THEN condition

    It sounds like you need your H9 check inside the loop, not once, before it.
    Try something like this:

    Please Login or Register  to view this content.

  3. #3
    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: IF THEN condition

    Notwithstanding the response you have received please note that your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    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.

  4. #4
    Registered User
    Join Date
    02-02-2017
    Location
    Caribbean
    MS-Off Ver
    2016
    Posts
    2

    Re: IF THEN condition

    Thanks. This worked.

+ 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] My vba Transpose with condition, but its transposing the condition from other range
    By Franky alta in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 09-28-2015, 03:56 PM
  2. Replies: 7
    Last Post: 06-01-2015, 06:05 PM
  3. Condition formatting of multiple condition formatted cells
    By merrin84 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 02-22-2015, 05:08 PM
  4. [SOLVED] IF the condition of gender is met AND the condition of age is met subtract this number
    By arsenalmom in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 01-16-2014, 11:16 PM
  5. [SOLVED] Help for if condition formula result only either hit or miss from mulitple condition
    By breadwinner in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 05-09-2013, 07:29 AM
  6. Replies: 6
    Last Post: 05-06-2010, 10:06 PM
  7. multi condition format? lookup and date condition valid for.
    By D_Rennie in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 08-13-2009, 11:37 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