Consulting

Results 1 to 6 of 6

Thread: VBA DataGrid User Form

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,954
    Location
    "You can use a Listbox or ComboBox with multiple columns. You can add each item individually or use RowSource or use List for addition by an array."

    Example with one listbox and one command button control:
    Private Sub UserForm_Initialize()
      Dim a() As Variant
      a() = [{"First", "Last"; "Kenneth", "Hobson"; "Jane", "Doe"}]
      
    With ListBox1
        .ColumnCount = UBound(a, 2)
        .BoundColumn = 2
        .List = a()
        .ListIndex = 1  'Select 2nd row
      End With
    End Sub
    
    Private Sub CommandButton1_Click()
      MsgBox "You chose: " & ListBox1.Value
      Unload Me
    End Sub
    You can use the BoundColumn property to get the SelectIedtem if needed.

    Of course, you can still use the flexgrid and spreadsheet controls but you would have to fill a sheet to show discontinuous data. Another option for the flexgrid method would be to export your data to an external file such as a csv file and use it as the datasource. It is faster than you might think.
    Last edited by SamT; 12-12-2014 at 01:38 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •