Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help Reviewing My Loop
Hi- Could you help me determine why this program is not looping correctly? In
particular, the loop problem is that it does not open the next kregfile in the for J loop. Thank you! Filo --------------------------------------- Sub REENTERDETAIL2() Dim deptnumber As String Dim j As Integer Dim Kregfile As String Dim x As String Application.ScreenUpdating = False Application.DisplayAlerts = False Rownumber = 21 For j = Rownumber To 22 ThisWorkbook.Activate Sheets(1).Activate Kregfile = Range("a" & j).Value If Range("a" & j).Value = "" Then Else Workbooks.Open Filename:=Kregfile, UpdateLinks:=0 x = ActiveWorkbook.Name MsgBox x Sheets(2).Select ActiveSheet.Unprotect "bud" deptnumber = Left(Range("A1").Value, 5) MsgBox deptnumber For z = 1 To 65530 ThisWorkbook.Activate Sheets("Detail").Select If Cells(z, "A").Value = deptnumber Then firstrow = z For m = 65530 To 1 Step -1 If Range("A" & m).Value = deptnumber Then lastrow = m For f = firstrow To lastrow MsgBox f ThisWorkbook.Activate Sheets("Detail").Select t = Range("B" & f).Value u = Range("F" & f).Value o = Range("G" & f).Value For y = 2 To 350 Workbooks(x).Activate Sheets(2).Select '" GRAND TOTAL - EXPENSES " If Range("A" & y).Value = t Then MsgBox t s = y y = 10000 Range("E" & s).Value = u Range("F" & s).Value = o Else End If Next y Exit For Next f End If Next m End If Next z End If Next j End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Help Reviewing My Loop
I haven't reviewed your logic (you should consider indenting your loops to
make your code more readable); however, that Exit For statement between your Next y and Next f statements looks wrong to me. Won't that jump out of the "f" loop immediately after the "y" loop finishes without giving the "f" loop the chance to execute more than one of its own iterations? Rick "Filo" wrote in message ... Hi- Could you help me determine why this program is not looping correctly? In particular, the loop problem is that it does not open the next kregfile in the for J loop. Thank you! Filo --------------------------------------- Sub REENTERDETAIL2() Dim deptnumber As String Dim j As Integer Dim Kregfile As String Dim x As String Application.ScreenUpdating = False Application.DisplayAlerts = False Rownumber = 21 For j = Rownumber To 22 ThisWorkbook.Activate Sheets(1).Activate Kregfile = Range("a" & j).Value If Range("a" & j).Value = "" Then Else Workbooks.Open Filename:=Kregfile, UpdateLinks:=0 x = ActiveWorkbook.Name MsgBox x Sheets(2).Select ActiveSheet.Unprotect "bud" deptnumber = Left(Range("A1").Value, 5) MsgBox deptnumber For z = 1 To 65530 ThisWorkbook.Activate Sheets("Detail").Select If Cells(z, "A").Value = deptnumber Then firstrow = z For m = 65530 To 1 Step -1 If Range("A" & m).Value = deptnumber Then lastrow = m For f = firstrow To lastrow MsgBox f ThisWorkbook.Activate Sheets("Detail").Select t = Range("B" & f).Value u = Range("F" & f).Value o = Range("G" & f).Value For y = 2 To 350 Workbooks(x).Activate Sheets(2).Select '" GRAND TOTAL - EXPENSES " If Range("A" & y).Value = t Then MsgBox t s = y y = 10000 Range("E" & s).Value = u Range("F" & s).Value = o Else End If Next y Exit For Next f End If Next m End If Next z End If Next j End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Reviewing Toolbar Default to Off | Excel Discussion (Misc queries) | |||
Reviewing Tool Bar | Excel Discussion (Misc queries) | |||
Reviewing Problem | Setting up and Configuration of Excel | |||
Reviewing Toolbar | Excel Discussion (Misc queries) | |||
reviewing toolbar always there... | Excel Discussion (Misc queries) |