View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Don Guillett[_4_] Don Guillett[_4_] is offline
external usenet poster
 
Posts: 2,337
Default rows that dont want to be deleted!!!!

if

Ndx=6
Range("A1:A" & Ndx).EntireRow.Delete


--
Don Guillett
SalesAid Software

"Ed" wrote in message
...
Range("A1:A6").EntireRow.Delete


Would that work as:

Range("A1:A" & Ndx).EntireRow.Delete ??

Ed

"Chip Pearson" wrote in message
...
Cecilia,

The reason is that when you delete row 1, what used to be row 2
now becomes row 1. Then the loop variable is incremented from 1
to 2, and the new row 2 (which used to be row 3) is deleted,
leaving the original row 2 (now row 1) in place. This behavior
repeats itself with each iteration of the loop.

When deleting rows in a loop, you should go in descending order:

Dim Ndx As Long
For Ndx = 6 To 1 Step -1
Rows(Ndx).Delete
Next Ndx

You could do this without a loop, of course.

Range("A1:A6").EntireRow.Delete


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"cecilia12345" wrote
in message ...
i have this code:
lets say numfilas is 6
i want to delete the first *6* rows

Sheets(2).Select
For i = 1 To NumFilas
Range("a1").EntireRow.Delete
Next i

it deletes some rows but some are just not deleted... why?

i have tried also
cells(i,1).entirerow.delete
and
row(i).delete


---
Message posted from http://www.ExcelForum.com/