Excel vba populate multicolumn listbox from range

JoePineapples
Beginner
Points270Trophies1Posts72
  • Jul 1st 2008
  • #1

Hi All


I have a userform That has Several client information textboxes on it including a textbox called txtClientID.


What I would like to do is add a multicolumn listbox to the form and populate it from a worksheet - "sheet3" Columns B to E. These records would be filtered by the txtClientID textbox [this would correspond to a client ID value in column E].


So I would have a listbox that contained all the records from Sheet 3 that relate to the Client ID on the userform.


Any help would be much appriciated.


JP

You can go anywhere you want if you look serious and carry a clipboard.

Kenneth Hobson
Super old
Likes Received17Points5,557Trophies2Posts1,846
  • Jul 1st 2008
  • #2

Re: Populate Multicolumn Listbox


The .List property is one way.

Code
  1. Private Sub txtClientId_Change[]
  2. FillLBGreaterThan txtClientId.Value, Me.ListBox1
  3. End Sub
  4. Private Sub UserForm_Initialize[]
  5. txtClientId.Value = 1000
  6. FillLBGreaterThan txtClientId.Value, Me.ListBox1
  7. End Sub
  8. Sub FillLBGreaterThan[idValue As Double, LB As MSForms.ListBox]
  9. Dim r As Range, c As Range, s As String
  10. Set r = Sheet3.Range["B2:" & Cells[Rows.Count, "B"].Address]
  11. LB.Clear
  12. LB.ColumnCount = 4
  13. For Each c In r
  14. If c.Offset[0, 3].Value > idValue Then
  15. LB.AddItem c.Value
  16. LB.List[LB.ListCount - 1, 1] = c.Offset[0, 1]
  17. LB.List[LB.ListCount - 1, 2] = c.Offset[0, 2]
  18. LB.List[LB.ListCount - 1, 3] = c.Offset[0, 3]
  19. End If
  20. Next c
  21. End Sub
Display More

Files

  • 95923 MultiColumn Listbox.zip

    [14.79 kB, downloaded 569 times, last: Yesterday, 1:21am]

[SIZE="2"]

Merge Or Convert Excel | Trading Add-ins For Excel | Convert Excel Into Web Pages | Convert Databases Including Excel | Business Spreadsheets | Build Automatic Trading Models in Excel [/SIZE]>

Video liên quan

Chủ Đề