Display list box entries

0 Agios

Well-known Member
Joined
Feb 22, 2004
Messages
570
Office Version
  1. 365
Is there a way to count how many items total a list box has ? and display that number in a label or text box ?

Thank you
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Yes

Code:
Label1.caption = Listbox1.Listcount

Assuming the Listbox is named Listbox1 and the Label is named Label1
 
Upvote 0
It is not clear where or what kind of ListBox you have. Momentman assumed it was on a UserForm. If it is on a worksheet, and if it is an ActiveX control, then you need to preface his Label1 and ListBox1 with a reference to the worksheet they are on. Assume that is Sheet1...

Sheets("Sheet1").Label1.Caption = Sheets("Sheet1").Listbox1.ListCount

If, on the other hand, they are Forms controls, then you would need to do it this way...

Sheets("Sheet1").Shapes("Label 7").OLEFormat.Object.Text = Sheets("Sheet1").Shapes("List Box 6").OLEFormat.Object.ListCount
 
Upvote 0
Thank you, I used that code in front of theother code, that was the problem :) somehow the list box has to be red first. Thank you guys
 
Upvote 0

Forum statistics

Threads
1,214,647
Messages
6,120,722
Members
448,987
Latest member
marion_davis

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