#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default combobox

i have a combobox bound to a named range. i have a
command button that runs the autofilter for the list the
combobox is bound to. after i filter the list i would
like to have combobox just display the filterd list. the
list is dynamic so i wrote a macro to resize list.

Public Sub List()
Dim test As Range
Sheets("sheet1").Activate
Sheets("sheet1").Range("a2").Select
Set test = ActiveCell.CurrentRegion
heads = test.ListHeaderRows
If heads 0 Then
Set test = test.Resize(test.Rows.Count - heads)
Set test = test.Offset(heads)
Sheets("sheet1").Range("a2").Select
test.Name = "test"
Sheets("sheet1").Columns.AutoFit
Set test = test.SpecialCells(xlCellTypeVisible)
End If

End Sub



i am trying to use this line of code to size the list to
just the visible rows... but of course it doesnt work...

Set test = test.SpecialCells(xlCellTypeVisible)

any suggestions?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default combobox

I think you'll want to cycle through those visible cells. I didn't see any code
for applying the filter and I assumed that the combobox was on the worksheet,
but this might get you started:

Option Explicit

Public Sub List()
Dim test As Range
Dim heads As Long
Dim myCell As Range

Sheets("sheet1").Activate
Sheets("sheet1").Range("a2").Select
Set test = ActiveCell.CurrentRegion
heads = test.ListHeaderRows
If heads 0 Then
Set test = test.Resize(test.Rows.Count - heads)
Set test = test.Offset(heads)
Sheets("sheet1").Range("a2").Select
test.Name = "test"
Sheets("sheet1").Columns.AutoFit

On Error Resume Next
Set test = test.SpecialCells(xlCellTypeVisible)
On Error GoTo 0

If test Is Nothing Then
'shouldn't happen?
Else
Worksheets("sheet1").ComboBox1.Clear
For Each myCell In test.Cells
Worksheets("sheet1").ComboBox1.AddItem myCell.Value
Next myCell
End If

End If

End Sub

jim c wrote:

i have a combobox bound to a named range. i have a
command button that runs the autofilter for the list the
combobox is bound to. after i filter the list i would
like to have combobox just display the filterd list. the
list is dynamic so i wrote a macro to resize list.

Public Sub List()
Dim test As Range
Sheets("sheet1").Activate
Sheets("sheet1").Range("a2").Select
Set test = ActiveCell.CurrentRegion
heads = test.ListHeaderRows
If heads 0 Then
Set test = test.Resize(test.Rows.Count - heads)
Set test = test.Offset(heads)
Sheets("sheet1").Range("a2").Select
test.Name = "test"
Sheets("sheet1").Columns.AutoFit
Set test = test.SpecialCells(xlCellTypeVisible)
End If

End Sub

i am trying to use this line of code to size the list to
just the visible rows... but of course it doesnt work...

Set test = test.SpecialCells(xlCellTypeVisible)

any suggestions?


--

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
fill combobox depending on selection from another combobox Adam Francis Excel Discussion (Misc queries) 2 July 24th 08 07:39 PM
combobox changes value flow23 Excel Discussion (Misc queries) 0 May 11th 06 04:44 PM
combobox value flow23 Excel Discussion (Misc queries) 0 April 26th 06 12:21 PM
combobox flow23 Excel Discussion (Misc queries) 3 April 21st 06 04:11 PM
ComboBox Abs Excel Discussion (Misc queries) 3 February 15th 06 02:05 AM


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