How to check if a row has nothing in it?

G

Guest

How do you check to see if a row has nothing in any of the cells in VBA?

I need to delete the row if there is nothing in it, and shift the rest of
the data up.
 
G

Guest

Sub gsnu()
Dim j As Long
Dim i As Long
Dim r As Range
Dim r2 As Range
Set r2 = ActiveSheet.UsedRange

j = r2.Rows.Count + r2.Row - 1
For i = 1 To j
If Application.CountA(Rows(i)) = 0 Then
If r Is Nothing Then
Set r = Rows(i)
Else
Set r = Union(r, Rows(i))
End If
End If
Next i

If Not r Is Nothing Then
r.EntireRow.Delete
End If
End Sub
 
D

Dave F

You could also do this with a formula, counting the blanks. =SUM(--
(ISBLANK(A1:Z1)) entered as an array formula sums all instances of
blank cells; if the sum equals 26 then you know the row is blank, etc.

This obviously is less automated than the VBA solution.

Dave
 

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