Results 1 to 6 of 6

Loop or For Each within a For Each

Threaded View

  1. #1
    Forum Contributor Rick_Stanich's Avatar
    Join Date
    11-21-2005
    Location
    Ladson SC
    MS-Off Ver
    Office365
    Posts
    1,177

    Loop or For Each within a For Each

    I am having some technical difficulties trying to place data onto sheet2. Sheet2 starts out blank, as sheet1 is proccessed it pastes data to sheet2. I have tried a "For Each" that failed only pasting data into Range "A1" for every found instance.

    In the code below, the area colored "Magenta", I need a Loop of some type that as data is pasted into column A on sheet2, it indexes to the next available cell and continues.
    How do I construct such a Loop or For Each with in the existing For Each?
    Sub aaa()
    If Left(ActiveWorkbook.Name, 3) = "MOT" Then
    
        'iTimeStart = Now()    'Time counter start to time macro
        With Sheets("Sheet1")    'Loop thru Column A
            Sh1LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
            Set Sh1Range = .Range("A10:A" & Sh1LastRow)
        End With
    
        With Sheets("Sheet2")    'Loop thru Column A
            Sh2LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
            Set Sh2Range = .Range("A1:A" & Sh2LastRow)
        End With
    
        For Each Sh1Cell In Sh1Range
            If IsNumeric(Sh1Cell.Offset(0, 3).Value) = True Then
                If Sh1Cell.Offset(0, 5).Comment Is Nothing Then
                    If Sh1Cell.Offset(0, 5).Value <> "" Then
                        sBubbleNumber = Sh1Cell.Offset(0, 3).Value
                        sDimValue = Sh1Cell.Offset(0, 5).Value
                        Sh1Cell.Activate
                        'add "For Each" or "Loop" for sheet2?
    
                                'Sh2Cell.Value = sBubbleNumber
                                'Sh2Cell.Offset(0, 1).Value = sDimValue
    
                        'MsgBox sBubbleNumber & " " & sDimValue    'for testing
                    End If
                End If
            End If
        Next Sh1Cell
    
    End If
    End Sub
    Any hints, tips or examples are welcome.
    Last edited by Rick_Stanich; 01-22-2010 at 12:56 PM.
    Regards

    Rick
    Win10, Office 365

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