PC Review


Reply
Thread Tools Rate Thread

another autofilter question

 
 
Gary Keramidas
Guest
Posts: n/a
 
      5th Nov 2007
i use these to give me a range of filtered data:

fRow = .CurrentRegion.Offset(1, 0).SpecialCells(xlCellTypeVisible).Row
lRow = .Cells(Rows.Count, "A").End(xlUp).Row
(these seem to always work and give me range of rows)

but when i use the following line to set a range, it doesn't work if there is
only 1 filtered row. it works if there is more than 1 row.
Set rng = ws.Range(ws.Cells(fRow, "I"), ws.Cells(lRow,
"I")).SpecialCells(xlCellTypeVisible)
i get something like this for the range:
$1:$5,$3762:$3762,$8375:$65536
you can see that 3762 is the one filtered row i want in this case.

how can i set the range if there is only 1 row of filtered data?



--


Gary



 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      6th Nov 2007
Option Explicit
Sub testme()

Dim VRng As Range

With ActiveSheet.AutoFilter.Range
If .Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count = 1 Then
'nothing but headers are visible
Set VRng = Nothing
Else
Set VRng = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
.Cells.SpecialCells(xlCellTypeVisible)
End If
End With

If VRng Is Nothing Then
MsgBox "nothing but headers"
Else
MsgBox VRng.Address & vbLf & _
"Is the address of the visible cells in the first column" & vbLf & _
VRng.EntireRow.Address
End If

End Sub


Gary Keramidas wrote:
>
> i use these to give me a range of filtered data:
>
> fRow = .CurrentRegion.Offset(1, 0).SpecialCells(xlCellTypeVisible).Row
> lRow = .Cells(Rows.Count, "A").End(xlUp).Row
> (these seem to always work and give me range of rows)
>
> but when i use the following line to set a range, it doesn't work if there is
> only 1 filtered row. it works if there is more than 1 row.
> Set rng = ws.Range(ws.Cells(fRow, "I"), ws.Cells(lRow,
> "I")).SpecialCells(xlCellTypeVisible)
> i get something like this for the range:
> $1:$5,$3762:$3762,$8375:$65536
> you can see that 3762 is the one filtered row i want in this case.
>
> how can i set the range if there is only 1 row of filtered data?
>
> --
>
> Gary


--

Dave Peterson
 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      6th Nov 2007
thanks dave, i'll take a look.

--


Gary


"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Option Explicit
> Sub testme()
>
> Dim VRng As Range
>
> With ActiveSheet.AutoFilter.Range
> If .Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count = 1 Then
> 'nothing but headers are visible
> Set VRng = Nothing
> Else
> Set VRng = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
> .Cells.SpecialCells(xlCellTypeVisible)
> End If
> End With
>
> If VRng Is Nothing Then
> MsgBox "nothing but headers"
> Else
> MsgBox VRng.Address & vbLf & _
> "Is the address of the visible cells in the first column" & vbLf & _
> VRng.EntireRow.Address
> End If
>
> End Sub
>
>
> Gary Keramidas wrote:
>>
>> i use these to give me a range of filtered data:
>>
>> fRow = .CurrentRegion.Offset(1, 0).SpecialCells(xlCellTypeVisible).Row
>> lRow = .Cells(Rows.Count, "A").End(xlUp).Row
>> (these seem to always work and give me range of rows)
>>
>> but when i use the following line to set a range, it doesn't work if there is
>> only 1 filtered row. it works if there is more than 1 row.
>> Set rng = ws.Range(ws.Cells(fRow, "I"), ws.Cells(lRow,
>> "I")).SpecialCells(xlCellTypeVisible)
>> i get something like this for the range:
>> $1:$5,$3762:$3762,$8375:$65536
>> you can see that 3762 is the one filtered row i want in this case.
>>
>> how can i set the range if there is only 1 row of filtered data?
>>
>> --
>>
>> Gary

>
> --
>
> Dave Peterson



 
Reply With Quote
 
Gary Keramidas
Guest
Posts: n/a
 
      7th Nov 2007
dave:

i think will workout fine. i changed the if statement to the following because i
create a collection for all unique items, so i know there is at least 1 item to
satisfy the filter created from each element of the collection. i just needed to
know when there was only 1 item.

If .Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count = 2 Then

thanks.

--


Gary


"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Option Explicit
> Sub testme()
>
> Dim VRng As Range
>
> With ActiveSheet.AutoFilter.Range
> If .Columns(1).SpecialCells(xlCellTypeVisible).Cells.Count = 1 Then
> 'nothing but headers are visible
> Set VRng = Nothing
> Else
> Set VRng = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
> .Cells.SpecialCells(xlCellTypeVisible)
> End If
> End With
>
> If VRng Is Nothing Then
> MsgBox "nothing but headers"
> Else
> MsgBox VRng.Address & vbLf & _
> "Is the address of the visible cells in the first column" & vbLf & _
> VRng.EntireRow.Address
> End If
>
> End Sub
>
>
> Gary Keramidas wrote:
>>
>> i use these to give me a range of filtered data:
>>
>> fRow = .CurrentRegion.Offset(1, 0).SpecialCells(xlCellTypeVisible).Row
>> lRow = .Cells(Rows.Count, "A").End(xlUp).Row
>> (these seem to always work and give me range of rows)
>>
>> but when i use the following line to set a range, it doesn't work if there is
>> only 1 filtered row. it works if there is more than 1 row.
>> Set rng = ws.Range(ws.Cells(fRow, "I"), ws.Cells(lRow,
>> "I")).SpecialCells(xlCellTypeVisible)
>> i get something like this for the range:
>> $1:$5,$3762:$3762,$8375:$65536
>> you can see that 3762 is the one filtered row i want in this case.
>>
>> how can i set the range if there is only 1 row of filtered data?
>>
>> --
>>
>> Gary

>
> --
>
> Dave Peterson



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autofilter Question kate Microsoft Excel Misc 0 25th Apr 2008 07:13 PM
Autofilter Question =?Utf-8?B?RGF2aWQ=?= Microsoft Excel Programming 0 18th May 2006 07:49 AM
AutoFilter Question Norg Bort Microsoft Excel Discussion 2 4th Jan 2006 08:02 AM
AUTOFILTER QUESTION =?Utf-8?B?RGFu?= Microsoft Excel Programming 1 2nd Mar 2005 04:36 PM
AutoFilter Question Michael Kintner Microsoft Excel Programming 2 6th Jan 2004 04:06 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:59 AM.