+ Reply to Thread
Results 1 to 3 of 3

Nested for each loops, moving to next cell on both simultaneously

Hybrid View

  1. #1
    Registered User
    Join Date
    01-20-2014
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    52

    Nested for each loops, moving to next cell on both simultaneously

    Hi all,

    I am trying to run 2 for each loops inside another loop, and I was wondering if there is a way to move to the next value for all loops at the same time.

    So when it reaches "Next starting, final, scal", all ranges move to the next cell before performing the formula.

    Sub blank()
    
    Dim scal As Range, final As Range, starting As Range, Distinct As Worksheet, Sheet57 As Worksheet, Lager As Workbook
    
    Set Lager = ActiveWorkbook
    Set Distinct = Sheets("Distinct Discounts")
    Set Sheet57 = Sheets("Sheet57")
    
    Sheets("Distinct Discounts").Select
    LLR = Range("A" & Rows.Count).End(xlUp).Row
    Sheets("Sheet57").Select
    Rw = Range("A" & Rows.Count).End(xlUp).Row
    
    Range("B2").Select
    
    For Each scal In Distinct.Range("B1:B" & LLR)
    For Each final In Distinct.Range("C1:C" & LLR)
    For Each starting In Distinct.Range("D1:D" & LLR)
        ActiveCell.FormulaR1C1 = _
            "=IF(COUNTBLANK('Weekly Promotions'!RC[" & starting.Value & "]:RC[" & final.Value & "])<" & scal.Value & ",1,0)"
        ActiveCell.Select
        Selection.AutoFill Destination:=Range(ActiveCell, cells(Rw, ActiveCell.Column))
    ActiveCell.Offset(0, 1).Select
    Next starting, final, scal
    
    End Sub
    Thanks in advance.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,168

    Re: Nested for each loops, moving to next cell on both simultaneously

    Is this solved?

    If you solve a problem yourself before anyone else has responded, please take a moment to describe your solution, chances are some other member will benefit.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    01-20-2014
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    52

    Re: Nested for each loops, moving to next cell on both simultaneously

    Hi arlu,

    yes I solved it in the end:


    Sub blank()
    Dim LLR as long, starting as Range, FINAL as range, scal as Range
    LLR = Range("A" & Rows.Count).End(xlUp).Row
    Range("B2").Select
    
    row_counter = 1
    
    Do
    Set starting = Distinct.Range("D" & row_counter)
    Set FINAL = Distinct.Range("C" & row_counter)
    Set scal = Distinct.Range("B" & row_counter)
    'MsgBox (scal)
    'MsgBox (starting)
    'MsgBox (final)
    
        ActiveCell.FormulaR1C1 = _
            "=IF(COUNTBLANK('Weekly Promotions'!RC[" & starting.value & "]:RC[" & FINAL.value & "])<" & scal.value - 1 & ",1,0)"
        ActiveCell.Select
        Selection.AutoFill Destination:=Range(ActiveCell, cells(Rw, ActiveCell.Column))
    ActiveCell.Offset(0, 1).Select
    row_counter = row_counter + 1
    Loop Until row_counter = LLR + 1
    
    Exit Sub

+ 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] Nested IF loops More than 7 Need Help
    By EricSomin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-31-2013, 02:25 PM
  2. [SOLVED] Nested Loops
    By Walter12 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-06-2012, 07:29 AM
  3. Nested loops VBA
    By zurich in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-06-2012, 03:21 PM
  4. Nested Do Loops
    By ross88guy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-08-2010, 09:10 AM
  5. [SOLVED] nested loops
    By jer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-15-2006, 05:15 PM

Tags for this Thread

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