View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
r r is offline
external usenet poster
 
Posts: 125
Default Looking to select noncontiguous rows with For loop

Sub Test_row_select()

Dim ZeroRow As Long, i As Long
Dim Rng As Excel.Range
With ActiveSheet
ZeroRow = 1000
For i = 13 To (ZeroRow - 7) Step 8
If TypeName(Rng) = "Nothing" Then
Set Rng = .Cells(i, 1).EntireRow
Debug.Print Rng.Address
Else
Set Rng = Application.Union(Rng, .Cells(i, 1).EntireRow)
End If
Next
Rng.Select
End With
End Sub

regards
r

Il mio ultimo lavoro ...
http://excelvba.altervista.org/blog/...ternative.html


"Bishop" wrote:

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?