ListBox Userform advice please

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
I am using the code below.

On the userform i enter ES into TextBox1
The results are them shown in the ListBox

One thing i notice is that there is no row number shown in the ListBox ?
If i select a value with no row number shown i see a RTE1004 Method range of object Global failed.

If i select a value which does have a row number then i am taken to that item on the worksheet.

What i dont understand is why there should be any entries without row numbers because my worksheet has row numbers obviously for each customer ?

PLEASE SEE SCREEN SHOTS

VBA Code:
Private Sub ListBox1_Click()
  Set sh = Sheets("POSTAGE")
  sh.Select
  Range("I" & ListBox1.List(ListBox1.ListIndex, 3)).Select
  Unload PostageUserNameSearch
End Sub
Private Sub TextBox1_Change()
  Dim r As Range, f As Range, Cell As String, added As Boolean
  Dim sh As Worksheet
 
  Set sh = Sheets("POSTAGE")
  sh.Select
  With ListBox1
    .Clear
    .ColumnCount = 4
    .ColumnWidths = "240;100;280;50"
    If TextBox1.Value = "" Then Exit Sub
    Set r = Range("I8", Range("I" & 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                 'Item
              .List(1, 3) = f.Row                 'Row Number
              .List(i, 2) = f.Offset(, -7).Value  'Customer
              .List(i, 1) = f.Offset(, -2).Text   'Date

              added = True
              Exit For
          End Select
        Next
        If added = False Then
              .AddItem f.Value                                 'Item
              .List(.ListCount - 1, 3) = f.Row                 'Row Number
              .List(.ListCount - 1, 2) = f.Offset(, -7).Value  'Customer
              .List(.ListCount - 1, 1) = f.Offset(, -2).Text   'Date
              
        End If
        Set f = r.FindNext(f)
      Loop While Not f Is Nothing And f.Address <> Cell
      TextBox1 = UCase(TextBox1)
      .TopIndex = 0
    Else
      MsgBox "NO USER NAME WAS FOUND USING THAT INFORMATION", vbCritical, "POSTAGE SHEET USER NAME SEARCH"
      TextBox1.Value = ""
      TextBox1.SetFocus
    End If
  End With
End Sub
 

Attachments

  • 6321.jpg
    6321.jpg
    209.9 KB · Views: 9
  • 6322.jpg
    6322.jpg
    35.8 KB · Views: 8

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Something i have noticed.

If i search for say PO i see now row number for the person in question.

BUT

If i search for POR then the same person is shown but this time a row number is shown

Weird ???
 
Upvote 0
Have a look at the code lines commented with 'Row Number and see where you're putting it in the list box.
 
Upvote 0
After about an hour i then spotted it even when you told me where to look i didnt see it at first.

I had a 1 where it should have been an i
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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