Lastrow... HELP!!!

B

Benoit

Hello,

I'm currently using this in a macro to remove any row
that are empty under column "A":

lastrow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Row
For row_index = lastrow - 1 To 1 Step -1
If Not IsNumeric(Cells(row_index, 1).Value) Then
Rows(row_index).Delete
End If

Now I would like to do the same thing but for column D,
after colomn A has been done.

What do I need to do???
 
T

Trevor Shuttleworth

lastrow = ActiveSheet.Cells(Rows.Count, 4).End(xlUp).Row
For row_index = lastrow - 1 To 1 Step -1
If Not IsNumeric(Cells(row_index, 4).Value) Then
Rows(row_index).Delete
End If
 
B

Benoit

It doesn't work.

Basically, what I wanna do is:

Firts, look in column A and everything that is not a
number (including blank cells), delete the entire row.
Second, look in column D and everything that is not a
number (including blank cells), delete the entire row.

Thanks!!!
 
B

Bob Phillips

For iCol = 1 To 4 STep 3
lastrow = ActiveSheet.Cells(Rows.Count, icol).End(xlUp).Row
For row_index = lastrow - 1 To 1 Step -1
If Not IsNumeric(Cells(row_index, iCol).Value) Then
Rows(row_index).Delete
End If
Next row_index
Next iCol
 
R

Ron de Bruin

Hi Benoit

Try this for column A and D

Sub Example1()
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim delrow As Variant

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

Firstrow = ActiveSheet.UsedRange.Cells(1).Row
Lastrow = ActiveSheet.UsedRange.Rows.Count + Firstrow - 1
With ActiveSheet
.DisplayPageBreaks = False
For Lrow = Lastrow To Firstrow Step -1
delrow = False
If IsError(.Cells(Lrow, "A").Value) Then
'Do nothing, This avoid a error if there is a error in the cell
ElseIf Not IsNumeric(.Cells(Lrow, "A").Value) Or _
.Cells(Lrow, "A").Value = "" Then delrow = True
End If

If IsError(.Cells(Lrow, "D").Value) Then
'Do nothing, This avoid a error if there is a error in the cell
ElseIf Not IsNumeric(.Cells(Lrow, "D").Value) Or _
.Cells(Lrow, "D").Value = "" Then delrow = True
End If

If delrow = True Then .Rows(Lrow).Delete
Next
End With
With Application
.ScreenUpdating = True
.Calculation = CalcMode
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

Top