View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Medemper Medemper is offline
external usenet poster
 
Posts: 26
Default Selecting Filtered records only when AutoFilter is on

I'm probably not the person to be answering this, but did you mean you want the rows that are hidden in the filter to be or to not be selected?

If maxrow is say 3, so that your range to select would be B12:F14 (maxrow+11), and say rows 12 and 13 are hidden because of filtering, you want only B14:F14 to be selected, or did you want B12:F14 to be selected even tho they are filtered?

As is, this macro would select B12:F14 even if rows 12 and 13 are filtered. If you would only want B14:F14 to be selected, your Range line should be:

Range("B" & currentrow & ":" & "F" & maxrow + 11).SpecialCells(xlCellTypeVisible).Select

HTH
"Owen Vickers" wrote in message om...
From an earlier posting on the same subject I found some useful code
that allows me to store the "visible" data/rows in a variable...
thanks to Dave Peterson for that!
The code I used is as follows:
Sub RefreshModel()

Dim rng As Range
Dim maxrow As Integer

Set rng = ActiveSheet.AutoFilter.Range

On Error Resume Next
Set rng = rng.Offset(1, 0).Resize(rng.rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
'rng = rng.SpecialCells(xlCellTypeVisible)


On Error GoTo 0

If rng Is Nothing Then
MsgBox "0 rows"
Else
maxrow = rng.Cells.Count
End If

ActiveSheet.Select
currentrow = 12
Range("B" & currentrow & ":" & "F" & maxrow + 11).Select

End Sub

I get the correct value in the variable for maxrow but it is not
selecting the correct range!
I want to select the range B12 to F:maxrow ...the number of visible
rows but I do not understand the Resize and Offset methods in the code
above meaning that the selction is not working properly and does not
select all the Filtered rows!

What am I missing or not understanding?

Owen