View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Custom Fill in Listbox

If your sheet layout requires other cell content outside the data table
the you could give the table a name (sheet level) and use that to load
the array...

Private Sub btnClientSearch_Click()
Dim vDataIn, n&, k&, Ndx&, vAns
vAns = Me.Range("C4").Value
If vAns = Empty Then Exit Sub
vDataIn = Me.Range("DataSrc")
With Me.lstClientSearch
.Clear: .ColumnCount = UBound(vDataIn, 2)
For n = LBound(vDataIn) To UBound(vDataIn)
If vDataIn(n, 2) = vAns Then
.AddItem vDataIn(n, 1)
For k = 0 To UBound(vDataIn, 2) - 1
.List(Ndx, k) = vDataIn(n, k + 1)
Next 'k
Ndx = Ndx + 1
End If
Next 'n
End With
End Sub

...where the range name "DataSrc" was defined (in the NameBox left of
the FormulaBar) as...

'sheet1'!DataSrc

...and assumes the data table is on Sheet1. Note that the sheetname is
wrapped in apostrophes, and the defined name is preceeded by the
exclamation character.

--
Garry

Free uenet access at http://www.eternal-september.org
Classic VB Users Regroup
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion