View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Filo Filo is offline
external usenet poster
 
Posts: 54
Default 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