Adding/removing rows in Excel

  • Thread starter Thread starter Don
  • Start date Start date
D

Don

Is there an easy way of making code change automatically
to make allowance for adding or removing rows in a
spreadsheet, without manually changing the code ?
 
Assume column A can be used to find the number of rows

set rng = Range(cells(1,1),cells(rows.count,1).End(xlup))

for each cell in rng

If you have a data table/database construct

set rng = range("a1").CurrentRegion

in either case

Dim lastrow as Long
lastrow = rng.rows(rng.row.count).row

for i = lastrow to 1 step -1
if cells(lastrow,1).Value = 0 then
cells(lastrow,1).EntireRow.Delete
end if
Next

as an example.
 
Back
Top