Listbox alternative where there is no drop down

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,717
Office Version
  1. 2007
Platform
  1. Windows
On a userform is there say a Listbox where you dont click the drop down or maybe a setting you can change so the results are just shown ?
Example like attched image

EaseUS_2024_10_26_15_45_11.jpg
 
This is where i am having the problem.
I have changed the text from the ComboBox now for the ListBox2.
When i open the userform i only see the customers name.
I should also see the date & item purchased.

This is the code, Do you see an error please.

VBA Code:
    Private Sub populate()
    
        ' clear the Listbox
        Me.ListBox2.Clear
        ' declare variables
        Dim i As Long, lRow As Long, ws As Worksheet
        ' set ws to the desired sheet
        Set ws = Application.Worksheets("POSTAGE")
        ' determine the last row of that desired sheet
        lRow = ws.Cells(Rows.count, 1).End(xlUp).Row
        
        ' populate the Listbox by looping down the rows of ws
        With Me.ListBox2
            For i = lRow To 8 Step -1
                'determine if this customer should be added to combobox list
                If UCase(ws.Cells(i, 7).Value) = "POSTED" Then
                    .AddItem Cells(i, 2)    'adds the customer name to combobox first column
                    .List(.ListCount - 1, 1) = Cells(i, 1) 'add the date to second column of line just added
                    .List(.ListCount - 1, 2) = Cells(i, 3) 'add the item to third column of line just added
                End If
            Next i
        End With
    
    End Sub

Customers name is in column B

Date is in column A

Item purchased is in column C
 
Upvote 0

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
So in respect to the column issus above ive added the following to the Private Sub UserForm_Initialize

VBA Code:
    With ListBox2
        .ColumnCount = 3
        .ColumnWidths = "250;130;100"
    End With

It now shows what i require.
Was that the correct thing to do or have i just created a workaround ?
Thanks
 
Upvote 0
I didnt use the column count in the properties field, so i hard coded it in the vba sheet

See attached.
Same thing i suppose ?
EaseUS_2024_10_29_14_16_44.jpg
 
Upvote 0
The default value of the columncount property in the listbox is 1. If you set 0 then it does not show you any columns.
If you don't use the property then you have to do it in the code.



1730213140228.png


🧙‍♂️
 
Upvote 0
Solution

Forum statistics

Threads
1,223,575
Messages
6,173,149
Members
452,503
Latest member
AM74

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