ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   How to check if a row has nothing in it? (https://www.excelbanter.com/excel-discussion-misc-queries/153243-how-check-if-row-has-nothing.html)

pokdbz

How to check if a row has nothing in it?
 
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.

Gary''s Student

How to check if a row has nothing in it?
 
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

--
Gary''s Student - gsnu200736


"pokdbz" wrote:

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.


Dave F[_2_]

How to check if a row has nothing in it?
 
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


On Aug 7, 9:08 am, pokdbz wrote:
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.





All times are GMT +1. The time now is 02:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com