Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Dim an array from a filtered Range

Would ultimately like to use array for userform combobox source.
Excel 2003
I seem to be having trouble with "non-consecutive" rows.
"Banging" my head. Any help would be appreciated. Thanks

Sub RangeFilter()

Dim w As Worksheet
Dim filterArray()
Dim currentFiltRange As String

Set w = Workbooks("My-Stuff.xls").Worksheets("My-Machines")
With w.ListObjects(1)

'filter the list (by column 5 data) based on userform textbox.text
currentFiltRange = .Range.AutoFilter(5, tbAcctNum.Text)
'sheet data is filtered correctly

MsgBox
w.ListObjects(1).DataBodyRange.SpecialCells(xlCell TypeVisible).Address
'Example result (based on selection)- $A$2:$P$4, $A$14:$P$32,
$A$36:$P$38
'visible results of filter. These addresses are correct.

ReDim filterArray(0 To f)
'An attempt to include only visible rows in an array

For f = 0 To .DataBodyRange.SpecialCells(xlCellTypeVisible).Row s.Count
'code to include ALL visible rows.
Next f

MsgBox f
'showing me number of visible rows for the above example as: 10
'incorrectly reporting number of visible rows (actual number of
rows: 13)
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Dim an array from a filtered Range

C,

If you sort your table and then filter it, you can use the filtered values from the range directly
as the rowsource of the combobox. I have assumed that you have a header row on your list.

Private Sub UserForm_Initialize()
Dim myR As Range
Dim myStr As String

Set myR = Workbooks("My-Stuff.xls").Worksheets("My-Machines").ListObjects(1).Range
myR.Sort Key1:=myR.Cells(1, 5), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
myR.AutoFilter Field:=5, Criteria1:=tbAcctNum.Text

Set myR = myR.Offset(1, 0).Resize(myR.rows.Count - 1) _
.SpecialCells(xlCellTypeVisible)
myStr = myR.Parent.Name & "!" & myR.Address
Me.ComboBox1.RowSource = myStr
myR.AutoFilter
End Sub



HTH,
Bernie
MS Excel MVP


"CBartman" wrote in message
...
Would ultimately like to use array for userform combobox source.
Excel 2003
I seem to be having trouble with "non-consecutive" rows.
"Banging" my head. Any help would be appreciated. Thanks

Sub RangeFilter()

Dim w As Worksheet
Dim currentFiltRange As String

Set w = Workbooks("My-Stuff.xls").Worksheets("My-Machines")
With w.ListObjects(1)

'filter the list (by column 5 data) based on userform textbox.text
currentFiltRange = .Range.AutoFilter(5, tbAcctNum.Text)
'sheet data is filtered correctly

MsgBox
w.ListObjects(1).DataBodyRange.SpecialCells(xlCell TypeVisible).Address
'Example result (based on selection)- $A$2:$P$4, $A$14:$P$32,
$A$36:$P$38
'visible results of filter. These addresses are correct.

ReDim filterArray(0 To f)
'An attempt to include only visible rows in an array

For f = 0 To .DataBodyRange.SpecialCells(xlCellTypeVisible).Row s.Count
'code to include ALL visible rows.
Next f

MsgBox f
'showing me number of visible rows for the above example as: 10
'incorrectly reporting number of visible rows (actual number of
rows: 13)
End With
End Sub



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
Redimming an array dynamically assigned from range (how to redim first dimension of a 2-D array? /or/ reverse the original array order) Keith R[_2_] Excel Programming 3 November 13th 07 04:08 PM
Array copying to a filtered region Jason Yang Excel Programming 8 February 22nd 07 01:09 PM
Filtered Array for Listbox Jim at Eagle Excel Programming 4 June 14th 06 04:37 PM
Trying to count text in a filtered array using this function dtg_denver Excel Programming 0 August 16th 05 02:39 AM
traversing through a filtered range based on another filtered range zestpt[_4_] Excel Programming 4 July 12th 04 06:37 PM


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