Yevette
Active Member
- Joined
- Mar 8, 2003
- Messages
- 336
Hello All,
Can one of you vba experts tell me what the code is that will automatically stop my macro if a run-time error occurs? Or perhaps you could tell me how to "better write" the following macro so I don't get an error at all. I have a list of cells with numbers and what the macro does is insert "x" number of rows based on whatever the number is in the row (above) the active cell. For example:
A1 = 8
A2 = 2
A3 = 5
A4 = 3
below A4 3 rows are inserted, below A3 5 rows are inserted, etc.
The macro works from the bottom up but errors out when it gets to the top (A1):
Sub FormatForm()
Range("A1").End(xlDown).Offset(1, 0).Activate
Do Until ActiveCell = "A1"
ActiveCell.Offset(-1, 0).Activate
Dim i As Integer
For i = 1 To ActiveCell.Offset(-1, 0).Value
ActiveCell.EntireRow.Insert
Next
Loop
End Sub
I'm sure it has something to do with my Do Until or maybe I need an Error On statement, but not quite sure. Help would be appreciated! Thanks a lot!
Can one of you vba experts tell me what the code is that will automatically stop my macro if a run-time error occurs? Or perhaps you could tell me how to "better write" the following macro so I don't get an error at all. I have a list of cells with numbers and what the macro does is insert "x" number of rows based on whatever the number is in the row (above) the active cell. For example:
A1 = 8
A2 = 2
A3 = 5
A4 = 3
below A4 3 rows are inserted, below A3 5 rows are inserted, etc.
The macro works from the bottom up but errors out when it gets to the top (A1):
Sub FormatForm()
Range("A1").End(xlDown).Offset(1, 0).Activate
Do Until ActiveCell = "A1"
ActiveCell.Offset(-1, 0).Activate
Dim i As Integer
For i = 1 To ActiveCell.Offset(-1, 0).Value
ActiveCell.EntireRow.Insert
Next
Loop
End Sub
I'm sure it has something to do with my Do Until or maybe I need an Error On statement, but not quite sure. Help would be appreciated! Thanks a lot!