+ Reply to Thread
Results 1 to 11 of 11

Help understanding Loops

  1. #1
    Registered User
    Join Date
    06-20-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    6

    Help understanding Loops

    Hi,

    I have the following requirement i need help with.

    I have this below statment that I need to repeat for a cell range I want to define as CellR1 (which will be Worksheet "Automation Range. B10:B20)
    but CellR2 also needs to increase to the next cell in its range everytime in repeats (which will be Worksheet "Automation Range. B30:B40)

    Please Login or Register  to view this content.
    exmaple, first run would be
    Please Login or Register  to view this content.

    second would be
    Please Login or Register  to view this content.
    and so on.

    I know there are mistakes in the above example..

    I am completely new to VBA so I do apoloagize.


    To explain further.
    what I need this to do is determine if Cell 1 (From Range 1) and Cell 1 (From Range 2) contain specific string, if so run rest of macro
    then this needs to repeat for each cell defined in Range 1

    Here is my code right now which is only looking at the first combinations of cells. removed some stuff for privacy.

    Please Login or Register  to view this content.
    Last edited by Leith Ross; 06-20-2012 at 12:58 AM. Reason: Added Code Tags

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: Help understanding Loops

    You should have posted a sample workbook. I think you need something like this:
    Please Login or Register  to view this content.
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    06-20-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Help understanding Loops

    Happy to attach entire sheet.

    Looking at the code you provided its not telling how to incrament using 2 different ranges (one for CellR1 and the second range for CellR2)

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: Help understanding Loops

    CellR1 in the For Each loop selects all the cells in range B10:B20.

    The CellR1.Offset(20, 0). ... looks at the cell 20 rows below the current CellR1 (and in the same column, as specified by the ",0") at the same time. Thus the offset selects B30:B40.
    Last edited by protonLeah; 06-20-2012 at 02:01 AM.

  5. #5
    Registered User
    Join Date
    06-20-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Help understanding Loops

    Ended up with this but no Joy.

    Please Login or Register  to view this content.

  6. #6
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,610

    Re: Help understanding Loops

    What did it not do? Your If statement is looking at B5 & B19 at the same time (then B6 & B20 ...) are those the right pairs? What's actually in those cells? Are they single word text strings "TRUE" and "NO"?
    Last edited by protonLeah; 06-20-2012 at 02:31 AM.

  7. #7
    Registered User
    Join Date
    06-20-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Help understanding Loops

    have attched a cropped down version of the sheets.
    Basically on sheet Automation if Condition 1 HIGH is TRUE and Condition 1 Sent Mail Log for High is NO then send email.
    repeat this for range B5:B14

    Hope this makes sense?
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    06-20-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Help understanding Loops

    Quote Originally Posted by protonLeah View Post
    What did it not do? Your If statement is looking at B5 & B19 at the same time (then B6 & B20 ...) are those the right pairs? What's actually in those cells? Are they single word text strings "TRUE" and "NO"?
    Both of the Cells B5 and B19 Contain the strings the correct strings "TRUE" and "NO" but the email didnt send.
    If I remove this IF statment and run the Macro the email sends as expected.

    Thanks again

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Help understanding Loops

    Like this:
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    06-20-2012
    Location
    Australia
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Help understanding Loops

    Thanks, that worked.

    One last question, if the statment is true (both conditions are met) how do i then change the value of the Offset Cell for that cycle of the Loop.
    want it to say " YES" so next time the macro runs it knows not to send email as its already been sent?

  11. #11
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Help understanding Loops

    Put this after the opening IF statement:
    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