Advice for why userform doesnt display values from worksheet column D

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,832
Office Version
  1. 2007
Platform
  1. Windows
Morning,
I am using the code below
My worksheet has values in columns ABCD
When the listbox on my userform is populated i only see values from columns ABC

Can you see what ive done wrong so column D isnt being shown


Rich (BB code):
Private Sub TextBox1_Change()
  TextBox1 = UCase(TextBox1)
  Dim r As Range, f As Range, cell As String, added As Boolean
  Dim sh As Worksheet
  
  Set sh = Sheets("KEYCODES")
  sh.Select
  With ListBox1
    .Clear
    .ColumnCount = 4
    .ColumnWidths = "250;100;120;120"
    If TextBox1.Value = "" Then Exit Sub
    Set r = Range("A3", Range("A" & Rows.Count).End(xlUp))
    Set f = r.Find(TextBox1.Value, LookIn:=xlValues, LookAt:=xlPart)
    If Not f Is Nothing Then
      cell = f.Address
      Do
        added = False
        For i = 0 To .ListCount - 1
          Select Case StrComp(.List(i), f.Value, vbTextCompare)
            Case 0, 1
              .AddItem f.Value, i
              .List(i, 1) = f.Offset(, 1).Value
              .List(i, 2) = f.Offset(, 2).Value
              .List(i, 3) = f.Offset(, 3).Value
              .List(i, 4) = f.Offset(, 4).Value
              added = True
              Exit For
          End Select
        Next
        If added = False Then
          .AddItem f.Value
          .List(.ListCount - 1, 1) = f.Offset(, 1).Value
          .List(.ListCount - 1, 2) = f.Offset(, 2).Value
          .List(.ListCount - 1, 3) = f.Offset(, 3).Value
          .List(.ListCount - 1, 4) = f.Offset(, 4).Value
        End If
        Set f = r.FindNext(f)
      Loop While Not f Is Nothing And f.Address <> cell
      TextBox1Search = UCase(TextBox1Search)
      .TopIndex = 0
      Else
      MsgBox "NO INFO WAS FOUND", vbCritical, "KEY CODE SEARCH MESSAGE"
      TextBox1.Value = ""
      TextBox1.SetFocus
    End If
  End With
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
That code will populate columns A:D in the listbox but it will not add column E that your code is trying to add since you set the listbox to 4 columns.
 
Upvote 0
Morning,
These forms always confuse me.
Can you edit / show the code i need to use.

Worksheet columns ABCD so Listbox needs to show values from columns ABCD

Currently i only see values from columns ABC
 
Upvote 0
I don't see how that is possible. Your code clearly loads columns A:E into the listbox. You won't see column E because the column count is set to 4. I have just tested and verified that that is what is happening. Perhaps your listbox isn't wide enough and you haven't scrolled across.
 
Upvote 0
See screenshot
The dracg icon if listbox isnt wide enough isnt show.

I dont understand about column E

Im an idiot as column D is empty ha ha
 

Attachments

  • EaseUS_2023_07_14_09_59_49.jpg
    EaseUS_2023_07_14_09_59_49.jpg
    36.7 KB · Views: 18
Upvote 0
The lines where you refer to .List(i, 4) or .List(.Listcount - 1, 4) are trying to add column E to the listbox. You can delete those.
 
Upvote 0

Forum statistics

Threads
1,224,813
Messages
6,181,114
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top