Adding/removing rows in Excel

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 ?
 
T

Tom Ogilvy

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.
 

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