Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 23
Default How to bind filtered data in list box?

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.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default How to bind filtered data in list box?

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
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
Bind a textbox to Access data Geo R Excel Discussion (Misc queries) 0 January 16th 08 04:45 PM
Getting data from a filtered list Gaetan Excel Discussion (Misc queries) 2 August 17th 07 02:02 PM
bind data to active x listbox without macro Ram Excel Discussion (Misc queries) 0 September 11th 06 07:46 PM
Select data in filtered list Stephen Rainey Excel Discussion (Misc queries) 2 July 28th 06 12:38 PM
Drop down list from filtered data Brady Excel Discussion (Misc queries) 6 June 28th 06 06:47 PM


All times are GMT +1. The time now is 01:18 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"