View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
PhilipsBernard PhilipsBernard is offline
external usenet poster
 
Posts: 7
Default What's wrong with this code?

Hi!

I'm kinda new to VBA programming, so maybe you can help me...

When I run the following macro, the program seems to crash (doesn't
respond). Is there a fault in the code or is there another explanation? All
advice welcome!

Sub FindActuals()



Actualmonth = Worksheets("COOMonthWCYTD").Range("J5")

'On Error GoTo codeBreak
'For i = 5 To 10
For LookupRow = 3 To Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
Set LookupAcc = Sheets(10).Cells(LookupRow, 2)
For rwIndex = 3 To 505
With Sheets(Actualmonth).Cells(rwIndex, 2)
Sheets(Actualmonth).Select
Sheets(Actualmonth).Cells(rwIndex, 2).Activate
If LookupAcc.Value = ActiveCell.Value Then
OffsetCount = -1
If Not ActiveCell.Offset(OffsetCount, -1) =
ActiveCell.Offset _(0, -1) - 1 Then

If LookupAcc.Offset(0, -1).Value =
ActiveCell.Offset _(OffsetCount, 0).Value Then
LookupAcc.Offset(0, 5).Value =
ActiveCell.Offset _(OffsetCount, 2).Value

Else: OffsetCount = OffsetCount - 1

End If
End If
End If
End With
Next rwIndex
Next LookupRow
'Next i
'codeBreak: Exit Sub
End Sub