Labels and multiple worksheets.

Shalbriri

Board Regular
Joined
Nov 4, 2010
Messages
93
Code:
Dim sh as Worksheet

For Each sh in ActiveWorkbook.Worksheets
sh.BlueLabel.Caption = sh.BlueLabel.Caption + 1
Next sh
i was hopeing this code would change every Label's caption named BlueLabel by value 1

but it doesn't work. but it should since the labels are ActiveX Controls and when code is written
Code:
BlueLabel.caption = BlueLabel.Caption +1
then this way it updates the labels value by 1

EDIT:
Forgot to add the error also:
compile error
Method or data member not found
 
Last edited:

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
This seems to work for me, using ActiveX control (although I prefer to use controls from the Forms menu).

Code:
Public Sub Test()
    Dim wks As Worksheet
    Dim lbl As MSForms.Label
    
    For Each wks In ThisWorkbook.Worksheets
        Set lbl = wks.OLEObjects("BlueLabel").Object
        lbl.Caption = lbl.Caption + 1
    Next wks
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,753
Members
452,940
Latest member
rootytrip

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