Results 1 to 6 of 6
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    looping or for next (2000)

    i want to loop all value in A for each date in column F?!?
    How to????
    tks.

    example:

    loop 0500 for 01/06/2008, 01/07/2008, 01/08/2008, 01/09/2008 finish
    goto the next
    loop 0501 for 01/06/2008, 01/07/2008, 01/08/2008, 01/09/2008 finish
    goto the next
    ...
    loop 6846 for 01/06/2008, 01/07/2008, 01/08/2008, 01/09/2008 finish
    finish the loop

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: looping or for next (2000)

    You didn't say what you wanted to do with it, so this just displays the values from each loop

    Steve
    <pre>Option Explicit
    Sub LoopAF()
    Dim rColA As Range
    Dim rA As Range
    Dim rColF As Range
    Dim rF As Range

    Set rColA = Range(Cells(2, 1), _
    Cells(Rows.Count, 1).End(xlUp))
    Set rColF = Range(Cells(2, 6), _
    Cells(Rows.Count, 6).End(xlUp))

    For Each rA In rColA
    For Each rF In rColF
    MsgBox rA & ", " & rF
    Next rF
    Next rA
    Set rA = Nothing
    Set rColA = Nothing
    Set rF = Nothing
    Set rColF = Nothing
    End Sub</pre>


  3. #3
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: looping or for next (2000)

    this is wath i want, work perfect!
    Tks.

  4. #4
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: looping or for next (2000)

    Sorry Steve i have modified your cod eto use also the column G, but i think not is Elegnat solution, have one?:

    Option Explicit
    Sub LoopAF()

    Dim rColA As Range
    Dim rA As Range
    Dim rColF As Range
    Dim rF As Range
    Dim LINEA As Long
    LINEA = 0

    Set rColA = Range(Cells(2, 1), Cells(Rows.Count, 1).End(xlUp))
    Set rColF = Range(Cells(2, 6), Cells(Rows.Count, 6).End(xlUp))

    For Each rA In rColA
    For Each rF In rColF
    Debug.Print rA & ", " & rF & "-" & Cells(2 + LINEA, 7)
    LINEA = LINEA + 1
    Next rF
    LINEA = 0
    Next rA

    Set rA = Nothing
    Set rColA = Nothing

    Set rF = Nothing
    Set rColF = Nothing

    End Sub

  5. #5
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: looping or for next (2000)

    There is no need for a new variable to keep track of the row. Just take my original and change the line:

    <pre>MsgBox rA & ", " & rF</pre>


    to

    <pre>Debug.Print rA & ", " & rF & " - " & rF.Offset(0, 1)</pre>



    Steve

  6. #6
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: looping or for next (2000)

    NICE, TKS!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •