PC Review


Reply
Thread Tools Rate Thread

How to bind filtered data in list box?

 
 
Vinod
Guest
Posts: n/a
 
      11th Jan 2010
Hi All,

I have developed a from in excel 2003 contains year dorpdown and listbox.
The list box source mapped/binded to a ragne and 'Year' dropdown has unique
years from the same range of listbox source.

My requirement is, if user selects year through 'Year' dropdown then the
list box has to refresh with selected year's data only. I tried to filter the
source data with selected 'Year' value but the listbox has been displaying
with old records i.e., still I see whole data includes hidden rows after
applying filter on source data.

I should not see the hidden rows in list box.

Is there any best method than implented or how to hide list box with hidden
rows from source range?

Please share your knowledge or thourghts in overcomeingt the issue which
will be appreciated.

Advanced Thanks,
~Vins.
 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      11th Jan 2010
You'll have to drop the rowsource for the year listbox.

Then you could loop through the filtered range and check to see if the row is
hidden. If it is visible then include it in the code to add the item to the
listbox -- or you could just look through the visible rows in that filtered
range...

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim VisRng As Range
Dim myRng As Range
Dim myCell as range

Set wks = ActiveSheet

me.listbox1.clear 'remove any existing list.

With wks
'just a single column. I used column A.
Set myRng = .Range("A1", .Cells(.Rows.Count, "A").End(xlUp))

'remove any existing filter
.AutoFilterMode = False
myRng.AutoFilter Field:=1, Criteria1:="whateveryouneeded"

With .AutoFilter.Range.Columns(1)
If .Cells.SpecialCells(xlCellTypeVisible) = 1 Then
MsgBox "only header visible"
Else
'avoid the header
Set VisRng = .Resize(.Cells.Count - 1).Offset(1, 0)
for each mycell in visrng.cells
me.listbox1.additem mycell.value
next mycell
End If
End With
.AutoFilterMode = False 'remove the filter
End With
End Sub

Untested, uncompiled. Watch for typos!

===============
Or you could drop the autofilter and just loop through the cells. If they match
a certain criteria, then use .additem to add it to the listbox.





Vinod wrote:
>
> Hi All,
>
> I have developed a from in excel 2003 contains year dorpdown and listbox.
> The list box source mapped/binded to a ragne and 'Year' dropdown has unique
> years from the same range of listbox source.
>
> My requirement is, if user selects year through 'Year' dropdown then the
> list box has to refresh with selected year's data only. I tried to filter the
> source data with selected 'Year' value but the listbox has been displaying
> with old records i.e., still I see whole data includes hidden rows after
> applying filter on source data.
>
> I should not see the hidden rows in list box.
>
> Is there any best method than implented or how to hide list box with hidden
> rows from source range?
>
> Please share your knowledge or thourghts in overcomeingt the issue which
> will be appreciated.
>
> Advanced Thanks,
> ~Vins.


--

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
how to bind images to a data list to create thumbnail =?Utf-8?B?bWhlcnJlcmE3OA==?= Microsoft VB .NET 0 26th Oct 2007 09:05 PM
Getting data from a filtered list =?Utf-8?B?R2FldGFu?= Microsoft Excel Misc 2 17th Aug 2007 02:02 PM
Select data in filtered list Stephen Rainey Microsoft Excel Misc 2 28th Jul 2006 12:38 PM
Reading data from a filtered list =?Utf-8?B?THVjYXMgU29sZXI=?= Microsoft Excel Programming 1 25th Apr 2005 06:52 PM
data bind list view? Brian Henry Microsoft VB .NET 1 2nd Mar 2004 03:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:48 AM.