Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Assigning AutoFiltered Range to Range Object

Hi,

I'm having trouble assigning an AutoFiltered Range of Data to a Range
Object. Here is my Code:

Sub PopulateValidationLists()
Range("ClientCells").Select
Dim theClientCode As String
Dim FilteredClients As Range
For Each Client In Range("ClientCells").Cells
Range("CustomerSolutions").AutoFilter Field:=9, Criteria1:="" &
Client.Value & ""
Set FilteredClients = Selection.AutoFilter.Range.Offset(1,
0).Resize(Selection.AutoFilter.Range.Rows.Count - 1)
Selection.AutoFilter.SpecialCells (xlCellTypeVisible)

Next
End Sub

The problem lies with this line of code:
Set FilteredClients = Selection.AutoFilter.Range.Offset(1,
0).Resize(Selection.AutoFilter.Range.Rows.Count - 1)
Selection.AutoFilter.SpecialCells (xlCellTypeVisible)

The error I receive is:
Object Required

Any ideas on how I can get around this?

Thanks.
Simon

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,480
Default Assigning AutoFiltered Range to Range Object

Hi Simon

I hit a similar problem some long while back.
I'm not sure this is the efficient way to do it, but it got me around the
problem and i have persisted with it since.
With wss having been set as the relevant sheet, and rng1 and rng2 dimmed as
ranges

Set rng1 = wss.AutoFilter.Range.Columns(1).Cells
Set rng1 = rng1.Offset(1, 0).Resize(rng1.Rows.Count - 1, 1)
Set rng2 = rng1.SpecialCells(xlVisible)

--
Regards
Roger Govier

"Simon" wrote in message
...
Hi,

I'm having trouble assigning an AutoFiltered Range of Data to a Range
Object. Here is my Code:

Sub PopulateValidationLists()
Range("ClientCells").Select
Dim theClientCode As String
Dim FilteredClients As Range
For Each Client In Range("ClientCells").Cells
Range("CustomerSolutions").AutoFilter Field:=9, Criteria1:="" &
Client.Value & ""
Set FilteredClients = Selection.AutoFilter.Range.Offset(1,
0).Resize(Selection.AutoFilter.Range.Rows.Count - 1)
Selection.AutoFilter.SpecialCells (xlCellTypeVisible)

Next
End Sub

The problem lies with this line of code:
Set FilteredClients = Selection.AutoFilter.Range.Offset(1,
0).Resize(Selection.AutoFilter.Range.Rows.Count - 1)
Selection.AutoFilter.SpecialCells (xlCellTypeVisible)

The error I receive is:
Object Required

Any ideas on how I can get around this?

Thanks.
Simon

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Assigning AutoFiltered Range to Range Object

If you filter out the first 100 rows of your data, and your filtered list has 10 values, then you
are trying to set FilteredClient to the visible cells of the first ten rows, all of which are
hidden.

Working with a filtered list, you should set a range to the full range (offset by 1, decreased by 1)
and then use the visible cells on that

Sub PopulateValidationLists2()
Range("ClientCells").Select
Dim theClientCode As String 'Not used
Dim FilteredClients As Range
Dim AllClients As Range

Set AllClients =
Range("CustomerSolutions").Offset(1,0).Resize(Rang e("CustomerSolutions").Rows.Count -1)

For Each Client In Range("ClientCells").Cells
Range("CustomerSolutions").AutoFilter Field:=9, Criteria1:=Client.Value
Set FilteredClients =- AllClients.SpecialCells(xlCellTypeVisible)
'Do something here with FilteredClients
Next
End Sub

HTH,
Bernie
MS Excel MVP


"Simon" wrote in message
...
Hi,

I'm having trouble assigning an AutoFiltered Range of Data to a Range
Object. Here is my Code:

Sub PopulateValidationLists()
Range("ClientCells").Select
Dim theClientCode As String
Dim FilteredClients As Range
For Each Client In Range("ClientCells").Cells
Range("CustomerSolutions").AutoFilter Field:=9, Criteria1:="" &
Client.Value & ""
Set FilteredClients = Selection.AutoFilter.Range.Offset(1,
0).Resize(Selection.AutoFilter.Range.Rows.Count - 1)
Selection.AutoFilter.SpecialCells (xlCellTypeVisible)

Next
End Sub

The problem lies with this line of code:
Set FilteredClients = Selection.AutoFilter.Range.Offset(1,
0).Resize(Selection.AutoFilter.Range.Rows.Count - 1)
Selection.AutoFilter.SpecialCells (xlCellTypeVisible)

The error I receive is:
Object Required

Any ideas on how I can get around this?

Thanks.
Simon



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Assigning AutoFiltered Range to Range Object

Hi Bernie,

With this line of code:
Set FilteredClients = AllClients.SpecialCells(xlCellTypeVisible)

How do I change it so I only return the visible items in column 8?

Thanks.
Simon

"Bernie Deitrick" wrote:

If you filter out the first 100 rows of your data, and your filtered list has 10 values, then you
are trying to set FilteredClient to the visible cells of the first ten rows, all of which are
hidden.

Working with a filtered list, you should set a range to the full range (offset by 1, decreased by 1)
and then use the visible cells on that

Sub PopulateValidationLists2()
Range("ClientCells").Select
Dim theClientCode As String 'Not used
Dim FilteredClients As Range
Dim AllClients As Range

Set AllClients =
Range("CustomerSolutions").Offset(1,0).Resize(Rang e("CustomerSolutions").Rows.Count -1)

For Each Client In Range("ClientCells").Cells
Range("CustomerSolutions").AutoFilter Field:=9, Criteria1:=Client.Value
Set FilteredClients =- AllClients.SpecialCells(xlCellTypeVisible)
'Do something here with FilteredClients
Next
End Sub

HTH,
Bernie
MS Excel MVP


"Simon" wrote in message
...
Hi,

I'm having trouble assigning an AutoFiltered Range of Data to a Range
Object. Here is my Code:

Sub PopulateValidationLists()
Range("ClientCells").Select
Dim theClientCode As String
Dim FilteredClients As Range
For Each Client In Range("ClientCells").Cells
Range("CustomerSolutions").AutoFilter Field:=9, Criteria1:="" &
Client.Value & ""
Set FilteredClients = Selection.AutoFilter.Range.Offset(1,
0).Resize(Selection.AutoFilter.Range.Rows.Count - 1)
Selection.AutoFilter.SpecialCells (xlCellTypeVisible)

Next
End Sub

The problem lies with this line of code:
Set FilteredClients = Selection.AutoFilter.Range.Offset(1,
0).Resize(Selection.AutoFilter.Range.Rows.Count - 1)
Selection.AutoFilter.SpecialCells (xlCellTypeVisible)

The error I receive is:
Object Required

Any ideas on how I can get around this?

Thanks.
Simon




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Assigning AutoFiltered Range to Range Object

Simon,

Try

Set FilteredClients = Intersect(Range("H:H"),
AllClients).SpecialCells(xlCellTypeVisible)

OR

Set FilteredClients = AllClients.Columns(8).SpecialCells(xlCellTypeVisib le)

Depends, of course, on what you mean by column 8... ;-)

HTH,
Bernie
MS Excel MVP


"Simon" wrote in message
...
Hi Bernie,

With this line of code:
Set FilteredClients = AllClients.SpecialCells(xlCellTypeVisible)

How do I change it so I only return the visible items in column 8?

Thanks.
Simon

"Bernie Deitrick" wrote:

If you filter out the first 100 rows of your data, and your filtered list
has 10 values, then you
are trying to set FilteredClient to the visible cells of the first ten
rows, all of which are
hidden.

Working with a filtered list, you should set a range to the full range
(offset by 1, decreased by 1)
and then use the visible cells on that

Sub PopulateValidationLists2()
Range("ClientCells").Select
Dim theClientCode As String 'Not used
Dim FilteredClients As Range
Dim AllClients As Range

Set AllClients =
Range("CustomerSolutions").Offset(1,0).Resize(Rang e("CustomerSolutions").Rows.Count
-1)

For Each Client In Range("ClientCells").Cells
Range("CustomerSolutions").AutoFilter Field:=9,
Criteria1:=Client.Value
Set FilteredClients =- AllClients.SpecialCells(xlCellTypeVisible)
'Do something here with FilteredClients
Next
End Sub

HTH,
Bernie
MS Excel MVP


"Simon" wrote in message
...
Hi,

I'm having trouble assigning an AutoFiltered Range of Data to a Range
Object. Here is my Code:

Sub PopulateValidationLists()
Range("ClientCells").Select
Dim theClientCode As String
Dim FilteredClients As Range
For Each Client In Range("ClientCells").Cells
Range("CustomerSolutions").AutoFilter Field:=9, Criteria1:="" &
Client.Value & ""
Set FilteredClients = Selection.AutoFilter.Range.Offset(1,
0).Resize(Selection.AutoFilter.Range.Rows.Count - 1)
Selection.AutoFilter.SpecialCells (xlCellTypeVisible)

Next
End Sub

The problem lies with this line of code:
Set FilteredClients = Selection.AutoFilter.Range.Offset(1,
0).Resize(Selection.AutoFilter.Range.Rows.Count - 1)
Selection.AutoFilter.SpecialCells (xlCellTypeVisible)

The error I receive is:
Object Required

Any ideas on how I can get around this?

Thanks.
Simon







  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Assigning AutoFiltered Range to Range Object

I'd use something like:

Option Explicit
Sub testme()
Dim wks As Worksheet
Dim VisRng As Range
Dim Client As Range
Dim ClientList As Range

Set wks = ActiveSheet

With wks
'remove any existing filter
.AutoFilterMode = False

Set ClientList = .Range("ClientCells")

For Each Client In ClientList.Cells
.Range("CustomerSolutions").AutoFilter Field:=9, _
Criteria1:="" & Client.Value & ""
With .AutoFilter.Range
If .Columns(1).Cells.SpecialCells(xlCellTypeVisible) _
.Count = 1 Then
MsgBox "only the headers are visible for client: " _
& Client.Value
Else
'resize to avoid the header
'and come down one row
Set VisRng = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
.Cells.SpecialCells(xlCellTypeVisible)
MsgBox Client.Value & vbLf & VisRng.Address(0, 0)
End If
End With
Next Client
End With
End Sub

Simon wrote:

Hi,

I'm having trouble assigning an AutoFiltered Range of Data to a Range
Object. Here is my Code:

Sub PopulateValidationLists()
Range("ClientCells").Select
Dim theClientCode As String
Dim FilteredClients As Range
For Each Client In Range("ClientCells").Cells
Range("CustomerSolutions").AutoFilter Field:=9, Criteria1:="" &
Client.Value & ""
Set FilteredClients = Selection.AutoFilter.Range.Offset(1,
0).Resize(Selection.AutoFilter.Range.Rows.Count - 1)
Selection.AutoFilter.SpecialCells (xlCellTypeVisible)

Next
End Sub

The problem lies with this line of code:
Set FilteredClients = Selection.AutoFilter.Range.Offset(1,
0).Resize(Selection.AutoFilter.Range.Rows.Count - 1)
Selection.AutoFilter.SpecialCells (xlCellTypeVisible)

The error I receive is:
Object Required

Any ideas on how I can get around this?

Thanks.
Simon


--

Dave Peterson
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
Top of AutoFiltered Range? Dave Birley Excel Programming 2 July 6th 07 01:02 PM
ASSIGNING THE VALUE TO A NAMED RANGE GIVING OBJECT DEFINED ERROR CAPTGNVR Excel Programming 8 February 16th 07 05:13 PM
Assigning an array to range object? Smitch Excel Programming 2 February 16th 07 03:10 PM
Assigning array to range inside Excel Object Jon Peltier Excel Programming 0 April 1st 04 11:14 PM
Selecting cells which do not meet a formatting criteria, and assigning a Range object to these. SuperJas Excel Programming 5 February 23rd 04 03:36 AM


All times are GMT +1. The time now is 10:12 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"