Hi Fiona,
If I follow this time it seems only necessary to check for PatRev names in
column-C cells, then get the whole row - right?
Also, if I understand, all these cells will include a SubTotal formula, that
will help a lot to restrict the search of named cells (see code).
In a new wb, first run SampleDataAndNames and see if the sample data & names
is something like what you are working with. Will be looking to copy data in
the yellow rows, but not the green rows which also have Subtotals and named
cells.
In GetFilteredData look at the SpecialCells line. This is like manually
select col-c, F5 > Special > Formulas tick only numbers & errors. Will that
work for you too, otherwise ignore and use the alternative commented rng.
Try both methods with bUseFilterMethod = True & Fasle
If True, fills column-P with True's in rows to filter, ie named cells in
col-c that start with PatRev. I've omitted the code to apply the filter and
copy to a new sheet but that will be very similar to the macro you posted
previously.
Probably, but depending on your data, the non-filter method will work just
as well if not better.
Sub SampleDataAndNames()
Dim b As Boolean
Dim i&, r As Range
Dim ws As Worksheet
Dim arr(1 To 23000, 1 To 1)
Set ws = Worksheets("Sheet4")
For i = 1 To UBound(arr)
arr(i, 1) = i
Next
For Each r In ws.Range("A1

23000").Columns
r.Value = arr
Next
With ws.Range("C1

23000")
For i = 100 To 23000 Step 100
.Rows(i).FormulaR1C1 = "=SUBTOTAL(9,R[-99]C:R[-1]C)"
b = Not b
If b Then
.Cells(i, 1).Name = "PatRev_C" & Right("0000" & i, 5)
.Rows(i).Interior.Color = vbYellow
Else
.Rows(i).Cells(1, 1).Name = "PatData_C" & Right("0000" & i,
5)
.Rows(i).Interior.Color = vbGreen
End If
Next
End With
End Sub
Sub GetFilteredData()
Dim b As Boolean
Dim i As Long, j As Long, cnt As Long
Dim lastRow As Long
Dim rng As Range, cel As Range
Dim wsFrom As Worksheet, wsTo As Worksheet
Dim bUseFilterMethod As Boolean ' for testing
Set wsFrom = ActiveWorkbook.Worksheets("Sheet4")
lastRow = wsFrom.Range("C" & wsFrom.Rows.Count).End(xlUp).Row
Set wsTo = ActiveWorkbook.Worksheets("Sheet2")
On Error Resume Next
'' Can we restrict search to formula cells like =SubTotal(
'' ( the 17 refers to numbers & errors in goto special Ctrl-F5)
Set rng = wsFrom.Columns("C:C").SpecialCells(xlCellTypeFormulas, 17)
If rng Is Nothing Then
MsgBox "no formulas in Col-C !"
Exit Sub
End If
''if can't use Specialcells will need to check all cells for names in
col-c
''23k cells will be slow, avoid if possible
'Set rng = wsFrom.Range("C1:C" & lastRow)
ReDim arridx(1 To rng.Count) As Long
i = 0
'' unnamed cells will error below, so do this with on
'' error resume next (already set above)
For Each cel In rng
b = LCase(Left(cel.Name.Name, 6)) = "patrev"
If b Then
i = i + 1
arridx(i) = cel.Row
cnt = cnt + 1
b = False
End If
Next
On Error GoTo 0
If cnt = 0 Then
MsgBox "no matching names found"
Exit Sub
ElseIf cnt < UBound(arridx) Then
ReDim Preserve arridx(1 To cnt)
End If
'bUseFilterMethod = True
If bUseFilterMethod Then
ReDim varr(1 To lastRow, 1 To 1)
For i = 1 To cnt
varr(arridx(i), 1) = True
Next
wsFrom.Range("P1:P" & lastRow).Value = varr
' set the filter on col-P for True,
' copy filtered range to new sheet
' remove the filter and clear contents in col-p
Else
ReDim arrCopy(1 To cnt, 1 To 15) ' 1 to 15 refers to cols a to o
With wsFrom.Range("a1

" & lastRow)
For i = 1 To cnt
For j = 1 To 15
arrCopy(i, j) = .Cells(arridx(i), j)
Next
Next
End With
wsTo.Range("a1

" & cnt).Value = arrCopy
End If
End Sub
Regards,
Peter T
"Fiona" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi Peter,
>
> Thanks again for your time. I'll try and be clearer....
>
> The worksheet shows financial data for just over 100 departments for
> several different time frames (the time frames are in the columns C to
> O). All the data is on one worksheet. Each department has the same
> categories of data, one of those categories is Patient Revenue.
> Patient Revenue is broken down into several rows of detail by (such as
> Insurance, Medi-Cal, Medicare, etc.). The Patient Revenue is
> subtotaled and each cell in that subtotal line is named using "PatRev"
> then a dept code, and a column prefix. So for instance, PatRev6010C,
> is the name for the cell that contains the Patient Revenue subtotal
> for dept. 6010 and the time frame in column C. I'd like to pull out
> all the patient revenue subtotal lines from all the departments and
> copy them to a second worksheet - this would be just over 100 rows -
> one for each department.
>
> So, my defined cell names do refer to a single cell. That single cell
> contains a subtotal. So, perhaps you're right that this will just be
> too many named cells across the entire range to do a fast search. I
> could limit the search to a single column - C - and if I find a cell
> with the name starting with "PatRev" then just copy that entire row of
> data to a new worksheet.
>
> The code I listed in my earlier message does this but only by
> searching each cell's value using the auto filter criteria line below:
>
> rng.AutoFilter Field:=1, Criteria1:="=Pat Rev Total"
>
> I'm trying to pull out a Pateint Revenue Subtotal line, and that line
> has no unique name in the value of the cells (such as "Patient Reveue
> SubTotal"). So, that is why I want to try and pull them out based on
> the cell names starting with "PatRev". Uisng VBA to do it would be
> great, I just don't know how to write the VBA code to tell the
> autofilter to search the cell defined names, not the cell values.
> Maybe it isn't possible?
>
> Thanks again for your time and I hope I have clarified it.
>
> Fiona
>
>
>
>
>
>