Looking to select noncontiguous rows with For loop
Well, to do it all at once like the code line I posted (again, ignoring the
Step 8 increment which I still don't see how it applies), you would need
something like this...
Rows(13).Resize(ZeroRow - 19).Delete
where the 19 would be a combination of the 7 that the OP wanted to subtract
from the ZeroRow value plus one to make the subtraction include the row at
both ends of the interval). I was going to post this solution, but figured
the Range method I presented would be easier to understand and remember in
future situations where it may be needed.
--
Rick (MVP - Excel)
"Patrick Molloy" wrote in message
...
rows(i).Delete
works too
"Rick Rothstein" wrote in message
...
Your question... the Step 8 part coupled with your statement "select ALL
rows from 13 to (ZeroRow - 7)"... is kind of confusing. However, I would
point out that you do not have to physically select a range in order to
delete it. This statement will delete ALL rows between (and including) 13
through ZeroRow-7...
Range("A13:A" & (ZeroRow - 7)).EntireRow.Delete
Note: Since we are deleting the entire row, it doesn't matter which
column we choose a cell from on that row in order to extend it through to
the entire row, so I used Column A.
--
Rick (MVP - Excel)
"Bishop" wrote in message
...
I have the following code:
For i = 13 To (ZeroRow - 7) Step 8
.Rows(i).Select
Next
.Selection.Delete
What I'm trying to do is select ALL rows from 13 to (ZeroRow - 7) THEN
delete them all at once. With the code written the way it is only the
very
last row selected will be deleted. How do I get a "hold the control
button
and select multiple rows" kind of selection using VBA code?
|