I didn't know you could do the rngdata(#index) to access information about the different areas.
that got me thinking and i was tinkering with your code and found that you can actually reference the next area in a for each loop.
originally i was trying to do
Datablock.areas(# index)...
which didn't work because each datablock only encompasses the current area it's on (assuming).
i then tried the
from your code in the for each loop and it worked. I just added a counter to the code to increment each time it goes through
Here is the code i put together to test it:
Sub CheckAreas()
Dim DataBlock As Range, rngData As Range
Dim rowoffset As Long, areaschecked As Long, rowsbetween As Long
Dim CurArea As Long, NextArea As Long, etad As Long, otad As Long, rtad As Long, qtad As Long
Range("A2").Select
Set rngData = ActiveCell.Range("A1:A30").SpecialCells(xlCellTypeVisible)
For Each DataBlock In rngData.areas
'''Find rows in current area and end sub if current area not factorable by 6 (if not cbool (mod6)
etad = DataBlock.Rows.Count 'test line not really needed
areaschecked = areaschecked + 1
rowsbetween = 0
'''Find rows between current area and next area and end sub if current area not factorable by 6 (if not cbool (mod6))
If areaschecked < rngData.areas.Count Then
CurArea = CurArea + 1
NextArea = CurArea + 1
'''Test'''
otad = rngData.areas(CurArea).Rows(1).Row
rtad = rngData.areas(NextArea).Rows(1).Row
'''End Test'''
rowsbetween = rngData.areas(NextArea).Rows(1).Row - (rngData.areas(CurArea).Row + rngData.areas(CurArea).Rows.Count)
End If
''Test line''
qtad = Range(DataBlock.Offset(etad, 0).Range("A1"), "STOPRC").Rows.Count - 1
MsgBox "DataBlock Address " & DataBlock.Address(RowAbsolute:=False, columnAbsolute:=False) _
& " area " & areaschecked & " has " & DataBlock.Rows.Count & " Rows" & vbCrLf _
& "And There are " & rowsbetween & " Rows between area " & areaschecked & " and the start of the next area"
Next
End Sub
I have no idea if a for each or for next loop is more efficient than one or the other but your code is admittedly much shorter though i'll be getting rid of all the test lines and message boxes so will cut down on it by a bunch. I wouldn't have known to try that though if it weren't for your code so i'll mark this as solved.
thanks
Bookmarks