Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default Increment cells only in filtered range?

This macro is supposed to increment down to the next visible cell in a
filtered range, then to the first empty cell below the filtered range. It's
based off code Tom Ogilvy gave me, but I must have changed something and I
can't find it. I call this macro within the loop of another macro. The
problem is that this doesn't stop when it hits the end of the filtered
range; instead, it loops back up to Row 1.



When stepping through, when the ActiveCell is in the last visible row of the
filtered range, on the third "Set rng =" line, "rng.count" is one more than
the row number of the ActiveCell. But when I step down to the next line
("On Error Resume Next"), I moused over rng.count and found it was 1. (I
don't understand what this "count" is counting - rows? cells? something
else?)



What I expected was the ActiveCell to become the first empty cell below the
filtered range. The calling macro then would detect the empty cell and end
its loop. What happens, though, is this macro selects back up to the top
left cell ("rng1(1).Select"), and never goes below the filtered range,
creating an endless loop.



How do I fix this to drop out of the filtered range?

Ed



Sub Increment1()
Dim rng As Range, rng1 As Range
Dim icol As Long
icol = ActiveCell.Column
Set rng = ActiveSheet.AutoFilter.Range
Set rng = Intersect(rng, Columns(icol))
Set rng = Range(ActiveCell.Offset(1, 0), rng(rng.count))
On Error Resume Next
Set rng1 = rng.SpecialCells(xlVisible)
On Error GoTo 0
If Not rng1 Is Nothing Then
rng1(1).Select
End If
End Sub




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Increment cells only in filtered range?

Sub AAIncrement1()
Dim rng As Range, rng1 As Range
Dim icol As Long
icol = ActiveCell.Column
Set rng = ActiveSheet.AutoFilter.Range
Set rng = Intersect(rng, Columns(icol))
Set rng = Range(ActiveCell.Offset(1, 0), rng(rng.Count))
On Error Resume Next
Set rng1 = rng.SpecialCells(xlVisible)
On Error GoTo 0
If Not rng1 Is Nothing Then
If rng1(1).Row = ActiveCell.Row Then
ActiveCell.Offset(1, 0).Select
Else
rng1(1).Select
End If
Else
rng(rng.Count).Offset(1, 0).Select
End If
End Sub

Might be what you want.

--
Regards,
Tom Ogilvy



"Ed" wrote in message
...
This macro is supposed to increment down to the next visible cell in a
filtered range, then to the first empty cell below the filtered range.

It's
based off code Tom Ogilvy gave me, but I must have changed something and I
can't find it. I call this macro within the loop of another macro. The
problem is that this doesn't stop when it hits the end of the filtered
range; instead, it loops back up to Row 1.



When stepping through, when the ActiveCell is in the last visible row of

the
filtered range, on the third "Set rng =" line, "rng.count" is one more

than
the row number of the ActiveCell. But when I step down to the next line
("On Error Resume Next"), I moused over rng.count and found it was 1. (I
don't understand what this "count" is counting - rows? cells? something
else?)



What I expected was the ActiveCell to become the first empty cell below

the
filtered range. The calling macro then would detect the empty cell and

end
its loop. What happens, though, is this macro selects back up to the top
left cell ("rng1(1).Select"), and never goes below the filtered range,
creating an endless loop.



How do I fix this to drop out of the filtered range?

Ed



Sub Increment1()
Dim rng As Range, rng1 As Range
Dim icol As Long
icol = ActiveCell.Column
Set rng = ActiveSheet.AutoFilter.Range
Set rng = Intersect(rng, Columns(icol))
Set rng = Range(ActiveCell.Offset(1, 0), rng(rng.count))
On Error Resume Next
Set rng1 = rng.SpecialCells(xlVisible)
On Error GoTo 0
If Not rng1 Is Nothing Then
rng1(1).Select
End If
End Sub






  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default Increment cells only in filtered range?

Tom - it works well, except when my filtered range is at the end of my used
range. I have slightly over 13,500 rows of data, with no blanks. I was
having trouble when I first started using the AutoFilter with filtering down
to the end of my used range, and someone told me to put something in a cell
in the row just below my used range; my data ends in 13,592, and A13593 has
"Last Row" in it.

When I filter for the block of data that goes down to 13592, this macro
iterates through all the visible cells (the outer macro starts the selection
in B1, then calls the AAIncrement1 to drop down into B2 and start the
evaluations). When it reaches the bottom, it jumps back up to A1 of the
header row (that being rng1(1).Select), and runs down to the bottom again.
Now it stops after the second time through, rather than looping
continuously, but it still has to run twice. With any other filtered range
that does not include that last data row, it runs once to the bottom of the
filtered data and stops.

Just to see, I commented out "On Error GoTo 0" and inserted
If Err.Number < 0 Then
MsgBox Err.Number
End If

Every time it hit the bottom of the visible range, I got a "1004" error.
Would it make sense to
If Err.Number = 1004 Then Exit Sub?
Ed

"Tom Ogilvy" wrote in message
...
Sub AAIncrement1()
Dim rng As Range, rng1 As Range
Dim icol As Long
icol = ActiveCell.Column
Set rng = ActiveSheet.AutoFilter.Range
Set rng = Intersect(rng, Columns(icol))
Set rng = Range(ActiveCell.Offset(1, 0), rng(rng.Count))
On Error Resume Next
Set rng1 = rng.SpecialCells(xlVisible)
On Error GoTo 0
If Not rng1 Is Nothing Then
If rng1(1).Row = ActiveCell.Row Then
ActiveCell.Offset(1, 0).Select
Else
rng1(1).Select
End If
Else
rng(rng.Count).Offset(1, 0).Select
End If
End Sub

Might be what you want.

--
Regards,
Tom Ogilvy



"Ed" wrote in message
...
This macro is supposed to increment down to the next visible cell in a
filtered range, then to the first empty cell below the filtered range.

It's
based off code Tom Ogilvy gave me, but I must have changed something and

I
can't find it. I call this macro within the loop of another macro. The
problem is that this doesn't stop when it hits the end of the filtered
range; instead, it loops back up to Row 1.



When stepping through, when the ActiveCell is in the last visible row of

the
filtered range, on the third "Set rng =" line, "rng.count" is one more

than
the row number of the ActiveCell. But when I step down to the next line
("On Error Resume Next"), I moused over rng.count and found it was 1.

(I
don't understand what this "count" is counting - rows? cells? something
else?)



What I expected was the ActiveCell to become the first empty cell below

the
filtered range. The calling macro then would detect the empty cell and

end
its loop. What happens, though, is this macro selects back up to the

top
left cell ("rng1(1).Select"), and never goes below the filtered range,
creating an endless loop.



How do I fix this to drop out of the filtered range?

Ed



Sub Increment1()
Dim rng As Range, rng1 As Range
Dim icol As Long
icol = ActiveCell.Column
Set rng = ActiveSheet.AutoFilter.Range
Set rng = Intersect(rng, Columns(icol))
Set rng = Range(ActiveCell.Offset(1, 0), rng(rng.count))
On Error Resume Next
Set rng1 = rng.SpecialCells(xlVisible)
On Error GoTo 0
If Not rng1 Is Nothing Then
rng1(1).Select
End If
End Sub








  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Increment cells only in filtered range?

Try this one:

Sub AAIncrement1()
Dim rng As Range, rng1 As Range
Dim icol As Long
icol = ActiveCell.Column
Set rng = ActiveSheet.AutoFilter.Range
Set rng = Intersect(rng, Columns(icol))
Set rng = Range(ActiveCell.Offset(1, 0), rng(rng.Count))
On Error Resume Next
Set rng1 = Intersect(rng, rng.SpecialCells(xlVisible))
On Error GoTo 0
If Not rng1 Is Nothing Then
If rng1(1).Row = ActiveCell.Row Then
ActiveCell.Offset(1, 0).Select
Else
rng1(1).Select
End If
Else
rng(rng.Count).Offset(1, 0).Select
End If
End Sub

--
Regards,
Tom Ogilvy


"Ed" wrote in message
...
Tom - it works well, except when my filtered range is at the end of my

used
range. I have slightly over 13,500 rows of data, with no blanks. I was
having trouble when I first started using the AutoFilter with filtering

down
to the end of my used range, and someone told me to put something in a

cell
in the row just below my used range; my data ends in 13,592, and A13593

has
"Last Row" in it.

When I filter for the block of data that goes down to 13592, this macro
iterates through all the visible cells (the outer macro starts the

selection
in B1, then calls the AAIncrement1 to drop down into B2 and start the
evaluations). When it reaches the bottom, it jumps back up to A1 of the
header row (that being rng1(1).Select), and runs down to the bottom again.
Now it stops after the second time through, rather than looping
continuously, but it still has to run twice. With any other filtered

range
that does not include that last data row, it runs once to the bottom of

the
filtered data and stops.

Just to see, I commented out "On Error GoTo 0" and inserted
If Err.Number < 0 Then
MsgBox Err.Number
End If

Every time it hit the bottom of the visible range, I got a "1004" error.
Would it make sense to
If Err.Number = 1004 Then Exit Sub?
Ed

"Tom Ogilvy" wrote in message
...
Sub AAIncrement1()
Dim rng As Range, rng1 As Range
Dim icol As Long
icol = ActiveCell.Column
Set rng = ActiveSheet.AutoFilter.Range
Set rng = Intersect(rng, Columns(icol))
Set rng = Range(ActiveCell.Offset(1, 0), rng(rng.Count))
On Error Resume Next
Set rng1 = rng.SpecialCells(xlVisible)
On Error GoTo 0
If Not rng1 Is Nothing Then
If rng1(1).Row = ActiveCell.Row Then
ActiveCell.Offset(1, 0).Select
Else
rng1(1).Select
End If
Else
rng(rng.Count).Offset(1, 0).Select
End If
End Sub

Might be what you want.

--
Regards,
Tom Ogilvy



"Ed" wrote in message
...
This macro is supposed to increment down to the next visible cell in a
filtered range, then to the first empty cell below the filtered range.

It's
based off code Tom Ogilvy gave me, but I must have changed something

and
I
can't find it. I call this macro within the loop of another macro.

The
problem is that this doesn't stop when it hits the end of the filtered
range; instead, it loops back up to Row 1.



When stepping through, when the ActiveCell is in the last visible row

of
the
filtered range, on the third "Set rng =" line, "rng.count" is one more

than
the row number of the ActiveCell. But when I step down to the next

line
("On Error Resume Next"), I moused over rng.count and found it was 1.

(I
don't understand what this "count" is counting - rows? cells?

something
else?)



What I expected was the ActiveCell to become the first empty cell

below
the
filtered range. The calling macro then would detect the empty cell

and
end
its loop. What happens, though, is this macro selects back up to the

top
left cell ("rng1(1).Select"), and never goes below the filtered range,
creating an endless loop.



How do I fix this to drop out of the filtered range?

Ed



Sub Increment1()
Dim rng As Range, rng1 As Range
Dim icol As Long
icol = ActiveCell.Column
Set rng = ActiveSheet.AutoFilter.Range
Set rng = Intersect(rng, Columns(icol))
Set rng = Range(ActiveCell.Offset(1, 0), rng(rng.count))
On Error Resume Next
Set rng1 = rng.SpecialCells(xlVisible)
On Error GoTo 0
If Not rng1 Is Nothing Then
rng1(1).Select
End If
End Sub










  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default Increment cells only in filtered range?

Tom - Sorry for the long hang time in a reply, but I do this through work
and your solution came after I had left. I just had a chance to test out
your solution, and it works great! Thank you.

If I may ask, when you do
Set rng = Range(ActiveCell.Offset(1, 0), rng(rng.Count))
what cell is identified by the rng(rng.Count) expression? I tried
rng(rng.Count).Select
to see if I could figure out what it does, but it didn't work.

Another head-scratcher - I set up this same workbook on a network, but it is
opened and search through a Visual Basic 6.0 interface. The VB app sets a
reference to the Excel object, and searches using the same code that gave me
problems - yet that way it works fine. Go figure!

Thanks for all your help, Tom.
Ed

"Tom Ogilvy" wrote in message
...
Try this one:

Sub AAIncrement1()
Dim rng As Range, rng1 As Range
Dim icol As Long
icol = ActiveCell.Column
Set rng = ActiveSheet.AutoFilter.Range
Set rng = Intersect(rng, Columns(icol))
Set rng = Range(ActiveCell.Offset(1, 0), rng(rng.Count))
On Error Resume Next
Set rng1 = Intersect(rng, rng.SpecialCells(xlVisible))
On Error GoTo 0
If Not rng1 Is Nothing Then
If rng1(1).Row = ActiveCell.Row Then
ActiveCell.Offset(1, 0).Select
Else
rng1(1).Select
End If
Else
rng(rng.Count).Offset(1, 0).Select
End If
End Sub

--
Regards,
Tom Ogilvy


"Ed" wrote in message
...
Tom - it works well, except when my filtered range is at the end of my

used
range. I have slightly over 13,500 rows of data, with no blanks. I was
having trouble when I first started using the AutoFilter with filtering

down
to the end of my used range, and someone told me to put something in a

cell
in the row just below my used range; my data ends in 13,592, and A13593

has
"Last Row" in it.

When I filter for the block of data that goes down to 13592, this macro
iterates through all the visible cells (the outer macro starts the

selection
in B1, then calls the AAIncrement1 to drop down into B2 and start the
evaluations). When it reaches the bottom, it jumps back up to A1 of the
header row (that being rng1(1).Select), and runs down to the bottom

again.
Now it stops after the second time through, rather than looping
continuously, but it still has to run twice. With any other filtered

range
that does not include that last data row, it runs once to the bottom of

the
filtered data and stops.

Just to see, I commented out "On Error GoTo 0" and inserted
If Err.Number < 0 Then
MsgBox Err.Number
End If

Every time it hit the bottom of the visible range, I got a "1004" error.
Would it make sense to
If Err.Number = 1004 Then Exit Sub?
Ed

"Tom Ogilvy" wrote in message
...
Sub AAIncrement1()
Dim rng As Range, rng1 As Range
Dim icol As Long
icol = ActiveCell.Column
Set rng = ActiveSheet.AutoFilter.Range
Set rng = Intersect(rng, Columns(icol))
Set rng = Range(ActiveCell.Offset(1, 0), rng(rng.Count))
On Error Resume Next
Set rng1 = rng.SpecialCells(xlVisible)
On Error GoTo 0
If Not rng1 Is Nothing Then
If rng1(1).Row = ActiveCell.Row Then
ActiveCell.Offset(1, 0).Select
Else
rng1(1).Select
End If
Else
rng(rng.Count).Offset(1, 0).Select
End If
End Sub

Might be what you want.

--
Regards,
Tom Ogilvy



"Ed" wrote in message
...
This macro is supposed to increment down to the next visible cell in

a
filtered range, then to the first empty cell below the filtered

range.
It's
based off code Tom Ogilvy gave me, but I must have changed something

and
I
can't find it. I call this macro within the loop of another macro.

The
problem is that this doesn't stop when it hits the end of the

filtered
range; instead, it loops back up to Row 1.



When stepping through, when the ActiveCell is in the last visible

row
of
the
filtered range, on the third "Set rng =" line, "rng.count" is one

more
than
the row number of the ActiveCell. But when I step down to the next

line
("On Error Resume Next"), I moused over rng.count and found it was

1.
(I
don't understand what this "count" is counting - rows? cells?

something
else?)



What I expected was the ActiveCell to become the first empty cell

below
the
filtered range. The calling macro then would detect the empty cell

and
end
its loop. What happens, though, is this macro selects back up to

the
top
left cell ("rng1(1).Select"), and never goes below the filtered

range,
creating an endless loop.



How do I fix this to drop out of the filtered range?

Ed



Sub Increment1()
Dim rng As Range, rng1 As Range
Dim icol As Long
icol = ActiveCell.Column
Set rng = ActiveSheet.AutoFilter.Range
Set rng = Intersect(rng, Columns(icol))
Set rng = Range(ActiveCell.Offset(1, 0), rng(rng.count))
On Error Resume Next
Set rng1 = rng.SpecialCells(xlVisible)
On Error GoTo 0
If Not rng1 Is Nothing Then
rng1(1).Select
End If
End Sub














  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Increment cells only in filtered range?

try this

Sub TestRange()
Dim rng As Range
Dim i As Long
Set rng = Range("A1:D3")
For i = 1 To rng.Count
rng(i).Select
MsgBox i & ", " & rng(i).Address & ", " & rng(i).Value
Next i
rng(1).Select
MsgBox "click OK to see rng(rng.count)"
rng(rng.Count).Select
MsgBox "rng.count: " & vbNewLine & _
rng.Count & ", " & rng(i).Address & ", " & rng(i).Value

End Sub

--
Regards,
Tom Ogilvy



"Ed" wrote in message
...
Tom - Sorry for the long hang time in a reply, but I do this through work
and your solution came after I had left. I just had a chance to test out
your solution, and it works great! Thank you.

If I may ask, when you do
Set rng = Range(ActiveCell.Offset(1, 0), rng(rng.Count))
what cell is identified by the rng(rng.Count) expression? I tried
rng(rng.Count).Select
to see if I could figure out what it does, but it didn't work.

Another head-scratcher - I set up this same workbook on a network, but it

is
opened and search through a Visual Basic 6.0 interface. The VB app sets a
reference to the Excel object, and searches using the same code that gave

me
problems - yet that way it works fine. Go figure!

Thanks for all your help, Tom.
Ed

"Tom Ogilvy" wrote in message
...
Try this one:

Sub AAIncrement1()
Dim rng As Range, rng1 As Range
Dim icol As Long
icol = ActiveCell.Column
Set rng = ActiveSheet.AutoFilter.Range
Set rng = Intersect(rng, Columns(icol))
Set rng = Range(ActiveCell.Offset(1, 0), rng(rng.Count))
On Error Resume Next
Set rng1 = Intersect(rng, rng.SpecialCells(xlVisible))
On Error GoTo 0
If Not rng1 Is Nothing Then
If rng1(1).Row = ActiveCell.Row Then
ActiveCell.Offset(1, 0).Select
Else
rng1(1).Select
End If
Else
rng(rng.Count).Offset(1, 0).Select
End If
End Sub

--
Regards,
Tom Ogilvy


"Ed" wrote in message
...
Tom - it works well, except when my filtered range is at the end of my

used
range. I have slightly over 13,500 rows of data, with no blanks. I

was
having trouble when I first started using the AutoFilter with

filtering
down
to the end of my used range, and someone told me to put something in a

cell
in the row just below my used range; my data ends in 13,592, and

A13593
has
"Last Row" in it.

When I filter for the block of data that goes down to 13592, this

macro
iterates through all the visible cells (the outer macro starts the

selection
in B1, then calls the AAIncrement1 to drop down into B2 and start the
evaluations). When it reaches the bottom, it jumps back up to A1 of

the
header row (that being rng1(1).Select), and runs down to the bottom

again.
Now it stops after the second time through, rather than looping
continuously, but it still has to run twice. With any other filtered

range
that does not include that last data row, it runs once to the bottom

of
the
filtered data and stops.

Just to see, I commented out "On Error GoTo 0" and inserted
If Err.Number < 0 Then
MsgBox Err.Number
End If

Every time it hit the bottom of the visible range, I got a "1004"

error.
Would it make sense to
If Err.Number = 1004 Then Exit Sub?
Ed

"Tom Ogilvy" wrote in message
...
Sub AAIncrement1()
Dim rng As Range, rng1 As Range
Dim icol As Long
icol = ActiveCell.Column
Set rng = ActiveSheet.AutoFilter.Range
Set rng = Intersect(rng, Columns(icol))
Set rng = Range(ActiveCell.Offset(1, 0), rng(rng.Count))
On Error Resume Next
Set rng1 = rng.SpecialCells(xlVisible)
On Error GoTo 0
If Not rng1 Is Nothing Then
If rng1(1).Row = ActiveCell.Row Then
ActiveCell.Offset(1, 0).Select
Else
rng1(1).Select
End If
Else
rng(rng.Count).Offset(1, 0).Select
End If
End Sub

Might be what you want.

--
Regards,
Tom Ogilvy



"Ed" wrote in message
...
This macro is supposed to increment down to the next visible cell

in
a
filtered range, then to the first empty cell below the filtered

range.
It's
based off code Tom Ogilvy gave me, but I must have changed

something
and
I
can't find it. I call this macro within the loop of another

macro.
The
problem is that this doesn't stop when it hits the end of the

filtered
range; instead, it loops back up to Row 1.



When stepping through, when the ActiveCell is in the last visible

row
of
the
filtered range, on the third "Set rng =" line, "rng.count" is one

more
than
the row number of the ActiveCell. But when I step down to the

next
line
("On Error Resume Next"), I moused over rng.count and found it was

1.
(I
don't understand what this "count" is counting - rows? cells?

something
else?)



What I expected was the ActiveCell to become the first empty cell

below
the
filtered range. The calling macro then would detect the empty

cell
and
end
its loop. What happens, though, is this macro selects back up to

the
top
left cell ("rng1(1).Select"), and never goes below the filtered

range,
creating an endless loop.



How do I fix this to drop out of the filtered range?

Ed



Sub Increment1()
Dim rng As Range, rng1 As Range
Dim icol As Long
icol = ActiveCell.Column
Set rng = ActiveSheet.AutoFilter.Range
Set rng = Intersect(rng, Columns(icol))
Set rng = Range(ActiveCell.Offset(1, 0), rng(rng.count))
On Error Resume Next
Set rng1 = rng.SpecialCells(xlVisible)
On Error GoTo 0
If Not rng1 Is Nothing Then
rng1(1).Select
End If
End Sub














  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default Increment cells only in filtered range?

When I tried your TestRange macro, Tom, it set the range to the 12 cells
that were included in A1:D3. But when I hit
MsgBox "click OK to see rng(rng.count)"

D3 was selected, but i had incremented to 13, as shown by
& rng(i).Address & ", " & rng(i).Value in the last MsgBox.

I added & i & ", " to confirm this. Is this as it should be?

Ed

"Tom Ogilvy" wrote in message
...
try this

Sub TestRange()
Dim rng As Range
Dim i As Long
Set rng = Range("A1:D3")
For i = 1 To rng.Count
rng(i).Select
MsgBox i & ", " & rng(i).Address & ", " & rng(i).Value
Next i
rng(1).Select
MsgBox "click OK to see rng(rng.count)"
rng(rng.Count).Select
MsgBox "rng.count: " & vbNewLine & _
rng.Count & ", " & rng(i).Address & ", " & rng(i).Value

End Sub

--
Regards,
Tom Ogilvy



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Increment cells only in filtered range?

a loop counter is incremented so the i being 13 is to be expected.

it is similar to

Sub Tester1()
i = 1
Do
Debug.Print i
'interior of the loop
i = i + 1

Loop Until i 12
Debug.Print " outside loop: " & i
End Sub



rng(rng.count) refers to the last cell in the range for a single area
range.

--
Regards,
Tom Ogilvy

"Ed" wrote in message
...
When I tried your TestRange macro, Tom, it set the range to the 12 cells
that were included in A1:D3. But when I hit
MsgBox "click OK to see rng(rng.count)"

D3 was selected, but i had incremented to 13, as shown by
& rng(i).Address & ", " & rng(i).Value in the last MsgBox.

I added & i & ", " to confirm this. Is this as it should be?

Ed

"Tom Ogilvy" wrote in message
...
try this

Sub TestRange()
Dim rng As Range
Dim i As Long
Set rng = Range("A1:D3")
For i = 1 To rng.Count
rng(i).Select
MsgBox i & ", " & rng(i).Address & ", " & rng(i).Value
Next i
rng(1).Select
MsgBox "click OK to see rng(rng.count)"
rng(rng.Count).Select
MsgBox "rng.count: " & vbNewLine & _
rng.Count & ", " & rng(i).Address & ", " & rng(i).Value

End Sub

--
Regards,
Tom Ogilvy





  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 118
Default Increment cells only in filtered range?

Thanks again, Tom. I really appreciate the time and explanations.
Ed

"Tom Ogilvy" wrote in message
...
a loop counter is incremented so the i being 13 is to be expected.

it is similar to

Sub Tester1()
i = 1
Do
Debug.Print i
'interior of the loop
i = i + 1

Loop Until i 12
Debug.Print " outside loop: " & i
End Sub



rng(rng.count) refers to the last cell in the range for a single area
range.

--
Regards,
Tom Ogilvy

"Ed" wrote in message
...
When I tried your TestRange macro, Tom, it set the range to the 12 cells
that were included in A1:D3. But when I hit
MsgBox "click OK to see rng(rng.count)"

D3 was selected, but i had incremented to 13, as shown by
& rng(i).Address & ", " & rng(i).Value in the last MsgBox.

I added & i & ", " to confirm this. Is this as it should be?

Ed

"Tom Ogilvy" wrote in message
...
try this

Sub TestRange()
Dim rng As Range
Dim i As Long
Set rng = Range("A1:D3")
For i = 1 To rng.Count
rng(i).Select
MsgBox i & ", " & rng(i).Address & ", " & rng(i).Value
Next i
rng(1).Select
MsgBox "click OK to see rng(rng.count)"
rng(rng.Count).Select
MsgBox "rng.count: " & vbNewLine & _
rng.Count & ", " & rng(i).Address & ", " & rng(i).Value

End Sub

--
Regards,
Tom Ogilvy







Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
calculate values in an unlimited range of cells in a column WITHOUTalso calculating values that had previously been filtered AGAINST? yadang Excel Discussion (Misc queries) 2 October 1st 09 06:18 PM
Count only cells within Filtered Range Corey Excel Worksheet Functions 5 January 26th 09 10:02 PM
sum of visable cells in filtered range RHino56 Excel Worksheet Functions 7 June 1st 08 10:13 PM
average of visible cells in a filtered range dave roth Excel Worksheet Functions 5 May 23rd 05 12:56 PM
Cells.Find in Auto-Filtered range mark Excel Programming 2 September 16th 03 11:55 PM


All times are GMT +1. The time now is 06:37 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"