userform help

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
On your userform, insert a listbox.

Within the sheet where your data is held, name the range by selecting the entire range of data and then in the upper-left creating a unique range name such as "ListboxRange" or whatever you can remember.

Within the design mode (in the VBA Window (Alt + F11)), select the listbox, right click and select properties. Within that properties there will be a "ListFillRange" field. In that field enter the same name "ListboxRange" name you had set earlier.

Once you have done this, set the columncount to 8, or however many columns you have and you are set. You can also set column widths if desired for each column by entering them in the field. 1"; 1"; 2"; etc.
 
Upvote 0
Great idea i can not find that listfillrange box to save my life, ill keep looking

On your userform, insert a listbox.

Within the sheet where your data is held, name the range by selecting the entire range of data and then in the upper-left creating a unique range name such as "ListboxRange" or whatever you can remember.

Within the design mode (in the VBA Window (Alt + F11)), select the listbox, right click and select properties. Within that properties there will be a "ListFillRange" field. In that field enter the same name "ListboxRange" name you had set earlier.

Once you have done this, set the columncount to 8, or however many columns you have and you are set. You can also set column widths if desired for each column by entering them in the field. 1"; 1"; 2"; etc.
 
Upvote 0
If it's a listbox on a userform try this - put it in the userform's module.
Code:
Option Explicit
Private Sub Userform_Initialize()
Dim rng As Range
Dim LastRow As Long
Dim LastCol As Long
Dim NoCols As Long
Dim colWidth As Long
Dim AllCols As String
 
    LastRow = Range("A" & Rows.Count).End(xlUp).Row
 
    LastCol = Cells(1, Columns.Count).End(xlToLeft).Column
 
    Set rng = Range("A1").Resize(LastRow, LastCol)
 
    NoCols = rng.Columns.Count
 
    colWidth = (ListBox1.Width - 10) / NoCols
 
    AllCols = String(NoCols, "X")
 
    AllCols = Replace(AllCols, "X", colWidth & ";")
 
    ListBox1.ColumnCount = NoCols
 
    ListBox1.ColumnWidths = AllCols
 
    ListBox1.List = rng.Value
 
End Sub
It assumes the data starts in A1 and should populate the listbox, set the no of columns, set the column widths etc programatically.

You probably don't need all that code eg if you know how may columns there are you can set that in design mode.
 
Upvote 0

Forum statistics

Threads
1,224,508
Messages
6,179,188
Members
452,893
Latest member
denay

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