Macros

K

Khalil Handal

Hi,

I have lot of textboxes and labels in a sheet in different places.
When I click any of the I will go to cell A.
i.e.
Private sub Label1_click()
Range("A1").Select
End sub

and

Private sub Label1_click()
Range("A1").Select
End sub

How can I use only ONE to all of these lables?
To be more clear: Is there something like:

Private sub Label1_click() , Label2_click , Label3_click()
Range("A1").Select
End sub

Can any one help?
 
D

Dave Peterson

There is another Label object on the Forms toolbar. It behaves differently than
the Label from the control Toolbox toolbar.

If I wanted all my labels to do the same (or even similar things), I'd use the
label from the Forms toolbar.

Then you can assign the same macro to each of the labels.

In a general module:

Option Explicit
Sub FormLabelClick()
Dim myLabel As Label

Set myLabel = ActiveSheet.Labels(Application.Caller)

With myLabel
.Parent.Range("a1").Select
End With

End Sub

You can assign the macro when you add the label or assign it later by
rightclicking on the label and choosing "assign macro".

And there are other differences between the Forms Label and the control toolbox
label. You may want to check to see if you can do all the important things you
want with the Forms version.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top