deleting rows programmatically

D

David Bateman

I import a large amount of data into excel unfortunately there are headers
or footers interspersed with the data. Sometimes the headers take up 10
rows
and sometimes it takes up 11. Would it be best to identify through the len
function which rows to delete? How would I programmatically remove them?
 
G

gocush

Can you differentiate a header row by, say text vs numeric
.... or
if the header in only in the first field (Column) while the data has multiple
fields (columns) ?

Does a header actually contain 10-11 rows or is it just wrapped text?
 
B

Bob Phillips

You need some rule to identify those rules, then it is simply a matter of
setting a range that meet the criteria, and delete the entirerow range.

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
T

Tom Ogilvy

If the len function will differentiate them then sure

lastrow = cells(rows.count,1).end(xlup).row
for i = lastrow to 1 step -1
if len(cells(i,1)) < 10 then
cells(i,1).EntireRow.Delete
end if
Next

if the number of cells filled in that row is the criteria

lastrow = cells(rows.count,1).end(xlup).row
for i = lastrow to 1 step -1
if application.countA(rows(i)) < 10 then
cells(i,1).EntireRow.Delete
end if
Next


Adjust the criteria in the IF statement to fit your situation.
 

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