View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson[_5_] Dave Peterson[_5_] is offline
external usenet poster
 
Posts: 1,758
Default Value of next visible mycell within a rng

Oh, oh.

I meant this:
For CellCtr = 1 To .Areas(AreaCtr).Cells.Count
just to loop through all the cells in that area.
(Some how I messed it up before I pasted into the post.)

Just for completeness:

Option Explicit
Sub testme()

Dim j As Long
Dim myRng As Range
Dim myCell As Range
Dim CellCtr As Long
Dim AreaCtr As Long
Dim NextCell As Range

'ActiveSheet.Rows(2).AutoFilter _
Field:=32, Criteria1:="" & CStr(SalesDate), Operator:=xlAnd

j = Cells(65536, 9).End(xlUp).Row
Set myRng = Range("I2:I" & j).SpecialCells(xlCellTypeVisible)

For AreaCtr = 1 To myRng.Areas.Count
With myRng
For CellCtr = 1 To .Areas(AreaCtr).Cells.Count
Set myCell = .Areas(AreaCtr).Cells(CellCtr)
Set NextCell = Nothing
If CellCtr = .Areas(AreaCtr).Cells.Count Then
If AreaCtr < myRng.Areas.Count Then
Set NextCell = .Areas(AreaCtr + 1).Cells(1)
Else
'out of cells, what to do?
End If
Else
Set NextCell = .Areas(AreaCtr).Cells(CellCtr + 1)
End If
If NextCell Is Nothing Then
MsgBox "MyCell is: " & myCell.Address(0, 0) & vbLf _
& "No next cell!"
Else
MsgBox "MyCell is: " & myCell.Address(0, 0) & vbLf _
& "NextCell is: " & NextCell.Address(0, 0)
End If
Next CellCtr
End With
Next AreaCtr

End Sub




Toppers wrote:

Dave,
I tried your code as a learning exercise ... and now understand
more about areas! .. but it appeared to me that it compared the last entry
in one area with the first in the next. It does not compare values within an
area as I expected i.e we are trying to compare consective values in
non-contiguous ranges.

Have I misunderstood what you are doing as the loop below only executes once
for each area.

Excuse my ignorance but I am trying to understand how this functionality
works.

For CellCtr = .Areas(AreaCtr).Cells.Count _
To .Areas(AreaCtr).Cells.Count

TIA.

<<snipped
--

Dave Peterson