Displaying information

JessyVal

New Member
Joined
Feb 23, 2021
Messages
30
Office Version
  1. 365
Hello,

Probably this is a very silly question, but I need some help

I have a form which was working well, showing me this information

1618924687670.png

In my excel sheet, Id was column 1, Name colum 2 and Last Name was Column 3. This is the code that I had:

VBA Code:
 With Worksheets("Registers")
   filas = .Range("A1").CurrentRegion.Rows.Count
   For i = 2 To filas
       If LCase(.Cells(i, 2).Value) Like "*" & LCase(Me.txtFiltro1.Value) & "*" Then
           j = j + 1
           Me.ListBox1.AddItem .Cells(i, 1)
           Me.ListBox1.list(Me.ListBox1.ListCount - 1, 1) = .Cells(i, 1).Offset(0, 1)
           Me.ListBox1.list(Me.ListBox1.ListCount - 1, 2) = .Cells(i, 1).Offset(0, 2)
       End If
   Next i
   If j = 0 Then MsgBox "Nothing found"
End With

but I had to add a New column in my sheet "Registers", so now Id is colum 2, Name is column 3 and Last Name is column 4, the problem is that the information is not being displayed properly, just shows me the Id but not name and last name.

1618924873880.png


This is the code that I am using now

VBA Code:
Private Sub CommandButton5_Click()
With Worksheets("Registers")
   filas = .Range("A1").CurrentRegion.Rows.Count
   For i = 3 To filas
       If LCase(.Cells(i, 3).Value) Like "*" & LCase(Me.txtFiltro1.Value) & "*" Then
           j = j + 1
           Me.ListBox1.AddItem .Cells(i, 2)
           Me.ListBox1.List(Me.ListBox1.ListCount - 1, 3) = .Cells(i, 1).Offset(0, 3)
           Me.ListBox1.List(Me.ListBox1.ListCount - 1, 4) = .Cells(i, 1).Offset(0, 4)
       End If
   Next i
   If j = 0 Then MsgBox "Nothing found"
End With
End Sub

I don't know if is something related to the form initialize, where I have this piece of code

VBA Code:
Private Sub UserForm_Initialize()
frmName.Show
Worksheets("Registers").Select
For i = 2 To 4
    Me.Controls("Label" & i) = Cells(3, i).Value
Next i

With ListBox1
    .ColumnCount = 3
    .ColumnWidths = "30 pt;50 pt;50 pt"
End With

End Sub

Thanks for the help in advance
 
Last edited by a moderator:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
It should be
VBA Code:
           Me.ListBox1.AddItem .Cells(i, 2)
           Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = .Cells(i, 1).Offset(0, 3)
           Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = .Cells(i, 1).Offset(0, 4)
 
Upvote 0
It should be
VBA Code:
           Me.ListBox1.AddItem .Cells(i, 2)
           Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = .Cells(i, 1).Offset(0, 3)
           Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = .Cells(i, 1).Offset(0, 4)
Hi, thanks ,
i wrote that code, and still the same, just displays the Id

1618931376928.png


I don't know if is related to the problem, but if I close the form, I get this message
1618931467075.png
 
Upvote 0
How about
VBA Code:
           Me.ListBox1.AddItem .Cells(i, 2).Value
           Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = .Cells(i, 3).Value
           Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = .Cells(i, 4).Value
 
Upvote 0
Solution
How about
VBA Code:
           Me.ListBox1.AddItem .Cells(i, 2).Value
           Me.ListBox1.List(Me.ListBox1.ListCount - 1, 1) = .Cells(i, 3).Value
           Me.ListBox1.List(Me.ListBox1.ListCount - 1, 2) = .Cells(i, 4).Value
works perfect!!

Thank you so much!!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,184
Members
452,615
Latest member
bogeys2birdies

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