title: How to Set Column Header and Format Columns in VBA ListBox?
body: <p>I have a <strong>userform</strong> with one <strong>TextBox</strong> and One <strong>ListBox</strong>.</p>
  <p><strong>TextBox1</strong> is for type query and <strong>ListBox1</strong> for Search Result.</p>
  <p>A data sheet is named &quot;<strong>DAY BOOK</strong>&quot;, where column D and H are a <em>date</em> fields.</p>
  <p>Below code works well, but displaying the search result</p>
  <ul>
  <li>the headerline disappears and</li>
  <li>date fields are shown as numbers before and after search (How to format the date columns)</li>
  </ul>
  <p>also required: First column of the <strong>DAY BOOK</strong> sheet empty.</p>
  <p>As newby any help will be appreciated.</p>
  <pre><code>Private Const LISTBOX_COL_COUNT As Long = 12
  'Option Explicit
  'Public EnableEvents As Boolean
  Public iWidth As Integer
  Public iHeight As Integer
  Public iLeft As Integer
  Public iTop As Integer
  Public bState As Boolean
  Dim BlnVal As Boolean
  
  Private Sub TextBox1_Change()
      PopulateListbox &quot;*&quot; &amp; TextBox1.Text &amp; &quot;*&quot;
  End Sub
  
  Private Sub userform_activate()
      With ListBox1
          .ColumnHeads = True
          .ColumnCount = LISTBOX_COL_COUNT
          '.ColumnWidths = &quot;20,35,70,50,50,60,60,50,50,0,0,60,60,60,0,60,60,40,35,60,45,60,60&quot;
      End With
      PopulateListbox
      TextBox1.SetFocus
  End Sub
  
  Private Sub PopulateListbox(Optional removeItem As String = vbNullString)
      Dim rng As Range
      Dim v() As Variant, listItems() As Variant
      Dim rowNum As Variant
      Dim rowList As Collection
      Dim r As Long, c As Long
      Dim itemText As String
      Dim isMatch As Boolean
  
      On Error GoTo pvs:
  
      'Define the target range.
      With Worksheets(&quot;DAY BOOK&quot;)
          Set rng = .Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp)).Resize(, LISTBOX_COL_COUNT)
      End With
  
      'Read the values into an array.
      v = rng.Value2
  
      'If no removals are required then just populate with the read array.
      If removeItem = vbNullString Then
          ListBox1.List = v
          Exit Sub
      End If
  
      'For removals find the list of matching rows in the array.
      Set rowList = New Collection
      For r = LBound(v, 1) To UBound(v, 1)
          isMatch = False
          For c = LBound(v, 2) To UBound(v, 2)
              itemText = LCase(CStr(v(r, c)))
              If itemText Like removeItem Then
                  isMatch = True
                  Exit For
              End If
          Next
          If isMatch Then rowList.Add r
      Next
      
      'Size the new list array, based on matching items.
      ReDim listItems(1 To rowList.Count, 0 To LISTBOX_COL_COUNT)
      
      'Copy the matchings rows to the new array.
      r = 1
      For Each rowNum In rowList
          For c = LBound(v, 2) To UBound(v, 2)
              listItems(r, c) = v(rowNum, c)
          Next
          r = r + 1
      Next
      
      'Populate the listbox with the new array.
      ListBox1.List = listItems
  
  pvs:
  TextBox1.SetFocus
  End Sub
  </code></pre>