Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 279
Default Referencing Cells in Multi-Area Range?

Good evening,

I use a filter to display selected subsets of rows in a large sreadsheet:

Dim r1 As Range

With xlSheet.Rows
.AutoFilter field:=1, Criteria1:=State
.AutoFilter field:=2, Criteria1:=Evt
Set r1 = .SpecialCells(xlCellTypeVisible)
End With

The spreadsheet shows exactly what I want, but r1 turns out to be a
multi-area range rather than a simple, single area rectabgle.

I'd love to be able to reference cells in r1 with something simple like:

r1.cells(1,2) or r1.cells(5,3)

but, that returns cells from the worksheet that are hidden, sort of "in
between" r1 areas. Items(n,m) doesn't work either. I've tried variations
other than specialcells, too.

Is there a simple way to reference r1 cells by row and column as they appear
on the screen?

I realize that I can loop through the areas, rows, and columns and build my
own 2D matrix, but I suspect there's an easy way to do this that I just
haven't uncovered.

Thanks in advance

Ed
  #2   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 279
Default Referencing Cells in Multi-Area Range?

This may be a case of bludgeoning the problem to death, but I came up with a
reasonable solution to simple indexing of a multi-area range.

First I declared a new class, fliteredRange, with:

Public fRange As Excel.Range

Function fCells(ByVal r As Long, ByVal c As Long) As Range
Dim rSub As Range

For Each rSub In fRange.Areas
If r 0 And r <= rSub.Rows.Count Then
Set fCells = rSub.Cells(r, c)
Exit Function
End If
r = r - rSub.Rows.Count
Next rSub
set fCells = Nothing
End Function

Then I set a filteredRange object to the autofiltered cells:

Dim thing as new filteredRange
Set thing.fRange = xlSheet.AutoFilter.Range.SpecialCells(xlCellTypeVi sible)

and index it thusly:

thing.fCells(1,2)

It needs a little more error checking, but that's the essence.

Ed
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
conditional formatting referencing 3 cells by row in a range TheMTCGal Excel Discussion (Misc queries) 3 December 8th 09 08:12 AM
Multi area Array using IRR function Malakite Excel Worksheet Functions 2 September 16th 09 01:32 PM
Multi-dimensional Array Referencing Fred Kalil Excel Programming 2 October 29th 05 01:46 PM
Referencing a Range of Cells Derek C New Users to Excel 3 August 10th 05 04:54 AM
multi workbook cell referencing Scot[_2_] Excel Programming 1 May 24th 04 10:19 PM


All times are GMT +1. The time now is 12:40 AM.

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

About Us

"It's about Microsoft Excel"