DilbertAsok
New Member
- Joined
- Feb 22, 2011
- Messages
- 8
Hi,
I'm fighting with VBA to improve my existing macro.
My current (working) macro - basically copies the top row downwards for 3000 rows, then moves on to the next sheet.
Which is fine, unless the top row of "Sheet1" contains an error (which can happen in cell B1 for example).
I want the macro to look at cell B1, if this is an error (will always be of the "#REF!" type), then delete row 1, LOOP back to look at B1, if this is an error, delete, LOOP back, until B1 isn't an error anymore, and then proceed with the macro above.
I've got this with the new code highlighted red, but it's not working...:
It doesn't seem to delete the rows even the first time, nevermind the Loop back to check again.
Any offers?
Thanks,
I'm fighting with VBA to improve my existing macro.
My current (working) macro - basically copies the top row downwards for 3000 rows, then moves on to the next sheet.
Code:
Sub IMPORT()
Sheets("Sheet1").Select
Range("A1:I1").Select
Selection.Copy
Range("A2:A3000").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheets("Sheet2").Select
Range("A1:I1").Select
Selection.Copy
Range("A2:A3000").Select
ActiveSheet.Paste
Application.CutCopyMode = False
etc etc etc
End Sub
Which is fine, unless the top row of "Sheet1" contains an error (which can happen in cell B1 for example).
I want the macro to look at cell B1, if this is an error (will always be of the "#REF!" type), then delete row 1, LOOP back to look at B1, if this is an error, delete, LOOP back, until B1 isn't an error anymore, and then proceed with the macro above.
I've got this with the new code highlighted red, but it's not working...:
Code:
Sub IMPORT()
Sheets("Sheet1").Select
[COLOR=red] Do
If IsError("B1") Then
Selection.Cell("A1").EntireRow.Delete
End If
Loop Until IsError("B1") = False
[/COLOR] Range("A1:I1").Select
Selection.Copy
Range("A2:A3000").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Sheets("Sheet2").Select
etc etc etc
End Sub
It doesn't seem to delete the rows even the first time, nevermind the Loop back to check again.
Any offers?
Thanks,