Results 1 to 11 of 11

Infinite Loop

Threaded View

  1. #1
    Registered User
    Join Date
    09-11-2007
    Posts
    41

    Infinite Loop

    hello all...

    i'm trying to loop through a bunch of worksheets and copy certain cells and paste it in a master sheet.

    Please take a look at my code below because it keeps copying the same thing over and over and is stuck in an infinite loop.

    For Each ws In ActiveWorkbook.Worksheets
        
        If ws.Visible = True Then
            ws.Activate
    
            Set rFind = Cells.Find(What:="Critical Activities / Watch List Items / and Milestones for Next 3 Months", After:=[A1], _
                                    LookIn:=xlValues, _
                                    lookat:=xlPart, _
                                    SearchOrder:=xlByRows, _
                                    SearchDirection:=xlNext, _
                                    MatchCase:=False, _
                                    SearchFormat:=False)
            If Not rFind Is Nothing Then
            'if it's the first sheet, copy the column headers, if not skip the headers
                If ActiveSheet.name = "A1 Replace Citichecking" Then
                    currentRow = rFind.Row + 1
                Else
                    currentRow = rFind.Row + 2
                End If
                'copy all rows until empty line, insert date and name
                'Do While Not IsEmpty(Cells(currentRow, 2))
                Do While (Cells(currentRow, 2) <> "Issues/Risks Log")
                    Select Case Cells(currentRow, 2)
                        Case Is = ""
                            currentRow = currentRow + 1
                        Case Is = "Major Milestones to Program End Date Beyond Current 3 Month Cycle (Maximum 10 Items)"
                            currentRow = currentRow + 1
                        Case Is = "26. Responsible Area / Owner"
                            currentRow = currentRow + 1
                        Case Else
                            Set rFindw = ActiveSheet.UsedRange.Find("Program Id", LookIn:=xlValues, lookat:=xlWhole)
                            currentRow = rFindw.Row + 1
                            strprogID = Range("K" & currentRow).Value
                            strcritical = "BCM"
                            strMileName = Range("C" & currentRow).Value
                            strMileStatus = Range("I" & currentRow).Value
                            strReason = Range("M" & currentRow).Value
                            strDescr = Range("D" & currentRow).Value
                            dtOrig = Range("G" & currentRow).Value
                            dtActual = Range("H" & currentRow).Value
                            strCommit = Range("L" & currentRow).Value
                            strMileCmmt = Range("N" & currentRow).Value
                            strRemCmmt = Range("O" & currentRow).Value
                            
                                If rFindw Is Nothing Then
                                    MsgBox "Not Found"
                                    Exit Sub
                                End If
                            dest.Range("A" & cursor).Value = strprogID
                            dest.Range("B" & cursor).Value = strcritical
                            dest.Range("C" & cursor).Value = strMileName
                            dest.Range("D" & cursor).Value = strMileStatus
                            dest.Range("E" & cursor).Value = strReason
                            dest.Range("F" & cursor).Value = strDescr
                            'dest.Range("F" & cursor).EntireColumn.WrapText = True
                            dest.Range("G" & cursor).Value = dtOrig
                            dest.Range("H" & cursor).Value = dtActual
                            dest.Range("I" & cursor).Value = strCommit
                            dest.Range("J" & cursor).Value = strMileCmmt
                            dest.Range("K" & cursor).Value = strRemCmmt
                            dest.Range("L" & cursor).Value = ActiveSheet.name
                            dest.Range("M" & cursor).Value = name
                            dest.Range("N" & cursor).Value = addDate
                                                    
                            
                            cursor = cursor + 1
                            currentRow = currentRow + 1
                        End Select
                Loop
    
            End If
        End If
    Next ws
    
    
    Worksheets("BCMs").Select
    'Delete columns GH in destination worksheet to fix merge issue
    Columns("G:H").Delete Shift:=xlToLeft
    Columns("J").Delete (xlToLeft)
    Thank you.
    Last edited by phong919; 01-22-2010 at 04:57 PM.

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