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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,810
Office Version
  1. 365
Platform
  1. Windows
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
 

Forum statistics

Threads
1,141,734
Messages
5,708,168
Members
421,549
Latest member
Dtcfire

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