CodyMonster
Board Regular
- Joined
- Sep 28, 2009
- Messages
- 159
Maybe someone can help me with this?
I have a loop going through a column to see if anything is not zero.
If there is an error in one of the cells I want is to go to the error handler and perform a set of statements.
However, I'm getting issues with the loop not ending as the variable will not end.
For example, if Lastrow = 10, when the next x runs it will continue to go to 11 or forever.
I don't know if I can use the GoTo label as I did. Using a If Than Else statement.
This isn't probably the prettiest script.. but it works (well, used too before I added the error handling).
Thanks for all the help if you can!!!
I have a loop going through a column to see if anything is not zero.
If there is an error in one of the cells I want is to go to the error handler and perform a set of statements.
However, I'm getting issues with the loop not ending as the variable will not end.
For example, if Lastrow = 10, when the next x runs it will continue to go to 11 or forever.
I don't know if I can use the GoTo label as I did. Using a If Than Else statement.
This isn't probably the prettiest script.. but it works (well, used too before I added the error handling).
Code:
Dim Lastrow As Integer
Lastrow = Sheets("Prior Data").Cells(Rows.Count, "B").End(xlUp).Row
Debug.Print Lastrow
For x = 1 To Lastrow
Debug.Print x
On Error GoTo ErrorLoop
Creditlimitamount = Sheets("Prior Data").Cells(x, 5).Value
If Creditlimitamount <> 0 Then
Sheets("Prior Data").Cells(x, 2).Resize(1, 8).Copy
Lastrowdiff = Sheets("differences").Cells(Rows.Count, 2).End(xlUp).Row + 1
Sheets("differences").Range("B" & Lastrowdiff).PasteSpecial xlValues
Sheets("differences").Range("B" & Lastrowdiff).PasteSpecial xlFormats
Sheets("differences").Range("A" & Lastrowdiff).Value = Date
End If
ErrorLoop:
If Application.WorksheetFunction.IsError(Sheets("Prior Data").Cells(x, 4)) Then
Sheets("Prior Data").Cells(x, 1).Resize(1, 3).Copy
Newcp = Sheets("Historical_Data").Cells(Rows.Count, 30).End(xlUp).Row + 1
Sheets("Historical_Data").Range("AD" & Newcp).PasteSpecial xlValues
Sheets("Historical_Data").Range("AD" & Newcp).PasteSpecial xlFormats
Else
Sheets("Prior Data").Cells(x, 1).Resize(1, 2).Copy
RemoveCp = Sheets("Historical_Data").Cells(Rows.Count, 34).End(xlUp).Row + 1
Sheets("Historical_Data").Range("AH" & RemoveCp).PasteSpecial xlValues
Sheets("Historical_Data").Range("AH" & RemoveCp).PasteSpecial xlFormats
Sheets("Prior Data").Cells(x, 4).Resize(1, 1).Copy
RemoveCp2 = Sheets("Historical_Data").Cells(Rows.Count, 36).End(xlUp).Row + 1
Sheets("Historical_Data").Range("AJ" & RemoveCp2).PasteSpecial xlValues
Sheets("Historical_Data").Range("AJ" & RemoveCp2).PasteSpecial xlFormats
End If
Skip:
Next x
Resume Skip
Thanks for all the help if you can!!!