error 424 runtime

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I got an error trying to run this script I want to delete the first and 3rd
row to make a flat file database sheet.
tia,


Sub deleteR1R3()
Dim LastRow As Range
With ActiveSheet
Set LastRow = Cells(Rows.Count, "A").End(xlUp).Row
If (LastRow = 1) And IsEmpty(Range("A1")) Then
Cells(3, "A").EntireRow.Delete
Cells(1, "A").EntireRow.Delete
End If
End With
End Sub
 
Without looking to close the first thing I notice is you declare LastRow to
be a range object but then try to assign a row number to it... Try this...

Sub deleteR1R3()
Dim LastRow As Long
With ActiveSheet
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
If (LastRow = 1) And IsEmpty(Range("A1")) Then
Cells(3, "A").EntireRow.Delete
Cells(1, "A").EntireRow.Delete
End If
End With
End Sub
 
Thanks, you are right. I see it now.

Jim Thomlinson said:
Without looking to close the first thing I notice is you declare LastRow to
be a range object but then try to assign a row number to it... Try this...

Sub deleteR1R3()
Dim LastRow As Long
With ActiveSheet
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
If (LastRow = 1) And IsEmpty(Range("A1")) Then
Cells(3, "A").EntireRow.Delete
Cells(1, "A").EntireRow.Delete
End If
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top