Results 1 to 3 of 3

Nested Loops

Threaded View

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

    Nested Loops

    I seem to be having trouble creating a nested loop. It seemed simple enough in my brain holder, however, in real life...Well I am here aren't I.

    Here is my code:
    Sub MissingDims()
        Dim Sh3LastRow    'Sht3LastRow
        Dim Sh3Range   'Sh3Range
        Dim Sh3Cell   'Sh3cell
    
        Dim Sh4LastRow    'Sht4LastRow
        Dim Sh4Range   'Sh4Range
        Dim Sh4Cell   'Sh4cell
    
        With Sheets("Sheet3")    'Loop thru Column E
            Sh3LastRow = .Cells(Rows.Count, "E").End(xlUp).Row
            Set Sh3Range = .Range("E6:E" & Sh3LastRow)
        End With
    
        With Sheets("Sheet4")    'Loop thru Column C
            Sh4LastRow = .Cells(Rows.Count, "C").End(xlUp).Row
            Set Sh4Range = .Range("C1:C" & Sh4LastRow)
        End With
    
        For Each Sh3Cell In Sh3Range
            If Sh3Cell.Value = "" Then
                sType = Sh3Cell.Offset(0, -4).Value
                For Each Sh4Cell In Sh4Range
                    Sh4Cell.Offset(0, 7).Value = sType
                    MsgBox Sh3Cell.Value
                Next Sh4Cell
            End If
        Next Sh3Cell
    End Sub
    I have gotten myself stuck in a loop for the code in red.

    I thought I was stepping from cell E6 of sheet3 and then cell J1 of sheet4 to each next respective cell. What I get is the first blank cell of "sType" is repeated on sheet4 column J for for X amount of cells.

    I am trying to list all blank cells from sheet3 column E to sheet 4 column J.

    Any hints, tips and or examples is appreciated. Humor is tolerated.
    Last edited by Rick_Stanich; 08-11-2009 at 04:15 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