+ Reply to Thread
Results 1 to 3 of 3

Thread: Advance two For Each at same time

  1. #1
    Forum Contributor
    Join Date
    07-23-2006
    Posts
    184

    Advance two For Each at same time

    I have these two named ranges, each 1 column by 32 rows.

    Each have data I need to use that is comparable row to row.

    I need to advance each For Each in each Range simultaneously.

    How can I make this statement work?
    For Each ofCell In Range("Order_Flavors")
      row = 2
      For Each fCell In Range("Flavors") And For Each Cell In Range("Expiration_Dates")
        If ofCell = fCell Then
          Do Until Cell.Value > 5
            Cells(row, column).Value = Cells(row, column).Value + 1
            j = j + 1
            k = k + 1 
          Loop
          Cells(row, column).Value = Cells(row, column).Value - k
          k = 0
       End If
      Next fCell And Next Cell
     row = row + 1
    Next ofCell
    Any suggestons?
    Thanks.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    2003 & 2007 & 2010
    Posts
    11,351
    Use a For Next loop rather than for For Each

    So more like,
    For Each ofCell In Range("Order_Flavors")
      Row = 2
      For lngindex = 1 To Range("Flavors").Rows.Count
        If ofCell = Range("Flavors").Cells(lngindex) Then
          Do Until Range("Expiration_Dates").Cells(lngindex).Value > 5
            Cells(Row, Column).Value = Cells(Row, Column).Value + 1
            j = j + 1
            k = k + 1
          Loop
          Cells(Row, Column).Value = Cells(Row, Column).Value - k
          k = 0
       End If
      Next
     Row = Row + 1
    Next ofCell
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    07-23-2006
    Posts
    184
    Appreciate Andy,

    I learned something new.

    I didn't know I could Index a Range like that.

    Thanks again.

+ 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.2.0