Find the range of a SubTotal

R

RWN

Is it possible to find the range that a SubTotal function refers to?

i.e. cell value is "=SUBTOTAL(9,J25:J31)"

Within the macro I want to determine the range of rows referred to in this cell (25->31).
 
D

Dave Peterson

As long as you're looking for cells on the same worksheet, you can look at
..precedents.

Option Explicit
Sub testme()

Dim myPrecedents
Dim myCell As Range

Set myCell = ActiveSheet.Range("a1")

With myCell
.Formula = "=SUBTOTAL(9,J25:J31)"
MsgBox .Precedents.Address(0, 0)
End With
End Sub
 
R

RWN

Thanks Dave;

That put me on the right track - missed a mental connection to "Precedents".
(was extracting from a "FormulaArray" but KNEW there had to be an easier way-if not 30
different ways.)

Turns out that;

Cells(StRow, StCol).Precedents.Select
For Each cl In Selection
' Do the tax exclusion using "Cells(cl.Row, cl.Column)"
Next

Is what I wanted

Again, thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top