Display list box entries

0 Agios

Well-known Member
Joined
Feb 22, 2004
Messages
538
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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Momentman

Well-known Member
Joined
Jan 11, 2012
Messages
4,142
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Yes

Code:
Label1.caption = Listbox1.Listcount

Assuming the Listbox is named Listbox1 and the Label is named Label1
 
Upvote 0

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
38,150
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
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

0 Agios

Well-known Member
Joined
Feb 22, 2004
Messages
538
Office Version
  1. 365
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,190,613
Messages
5,981,928
Members
439,743
Latest member
KatieO

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
Top