LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default AutoFilter _FilterDatabase Rowsource Listbox

You should add:

Option Explicit
to the top of your module.

You have some variables that use Rng and/or Range.
Dim myFilterRng As Range
Set myFilterRange = ....

The "option explicit" will catch those typos for you and could save you lots of
time later.

And to add to Jim's post, you'd want to do something like this:

listbox1.rowsource = myvisiblerange.address(external:=true)

but this won't work if your range is discontiguous. I think you'll have to loop
through those visible cells and .additem each value.

Option Explicit
Private Sub UserForm_Initialize()
Dim myVisibleRng As Range
Dim myFilterRng As Range
Dim myCell As Range
Dim cCtr As Long

Set myFilterRng = Sheet1.Range("a1:e13000")
'instead of 13000 rows, can you use a column (like A) to determine
'the lastrow?
'with sheet1
' set myfilterrng _
= .range("a1:e" & .cells(.rows.count,"A").end(xlup).row)
'end with

myFilterRng.AutoFilter Field:=5, Criteria1:="18650"

If myFilterRng.Columns(1) _
.SpecialCells(xlCellTypeVisible).Cells.Count = 1 Then
'no details found
Exit Sub
End If

With myFilterRng
Set myVisibleRng = .Resize(.Rows.Count - 1, 1) _
.Offset(1, 0).Cells _
.SpecialCells(xlCellTypeVisible)
End With

Debug.Print myVisibleRng.Address
With ListBox1
.ColumnCount = 5
For Each myCell In myVisibleRng.Cells
.AddItem myCell.Value
For cCtr = 2 To 5 'B:E
.List(.ListCount - 1, cCtr - 1) _
= myCell.Offset(0, cCtr - 1).Value
Next cCtr
Next myCell
End With
End Sub





hgdev wrote:

Excel 2000

I am trying to get AutoFilter data into a ListBox.
The below code gives me an "Type mismatch" error when I try to add the
Listbox Rowsource line. I read about using _FilterDatabase but could
not get the right syntax.

Private Sub UserForm_Initialize()
Dim myVisibleRng As Range
Dim myFilterRng As Range
Set myFilterRange = Sheet1.Range("a1:e13000")
myFilterRange.AutoFilter Field:=5, Criteria1:="18650"
Set myVisibleRange = myFilterRange.SpecialCells(xlCellTypeVisible)
Debug.Print myVisibleRange.Address
ListBox1.RowSource = myVisibleRange '<--type mismatch
End Sub

Thanks.


--

Dave Peterson



 
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
???Help??? Userform.Listbox.rowsource = ??? Steve Sparti Excel Discussion (Misc queries) 0 March 1st 06 09:44 PM
RowSource in ListBox aet-inc[_2_] Excel Programming 1 December 3rd 03 12:41 AM
ListBox Rowsource Limitation?? Dave Baranas Excel Programming 2 September 29th 03 05:01 PM
Is refreshing listbox rowsource in listbox click event possible? Jeremy Gollehon[_2_] Excel Programming 4 September 25th 03 06:45 PM
listbox rowsource Christy[_2_] Excel Programming 4 September 20th 03 11:44 PM


All times are GMT +1. The time now is 04:32 PM.

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"