Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    assign macro to the label in userform.... (2000 sr 1)

    I have this sheet and userform STAT.
    In the userform are present variuos label (AG. 4500, AG. 4501....) and i have insert into event click label a macro...
    Inested to repeat this block for each label is possible to use a code similar For Each or For Next for all label..?
    Hope i am clear...

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: assign macro to the label in userform.... (2000 sr 1)

    You could create one procedure and call it from the On Click event of all the labels:

    Private Sub Label_Click(n As Integer)
    Dim RIGA As String
    Dim CONTA As Long
    RIGA = 3
    Do While Not Range("A" & RIGA) = ""
    If Range("A" & RIGA) = Right(Me.Controls("Label" & n).Caption, 4) Then
    Call CERCA(RIGA, CONTA)
    End If
    RIGA = RIGA + 1
    Loop
    MsgBox CONTA
    End Sub

    Private Sub Label1_Click()
    Label_Click 1
    End Sub

    Private Sub Label2_Click()
    Label_Click 2
    End Sub

    ...

    Private Sub Label101_Click()
    Label_Click 101
    End Sub

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: assign macro to the label in userform.... (2000 sr 1)

    Or use a class module?
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  4. #4
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: assign macro to the label in userform.... (2000 sr 1)

    good!...

    Assuming i have clicked on one of this label and the macro is finished is possible to colorize the label (with a different color to the default) in this mode i uderstand for the label colored i have alreday completed the activity...

  5. #5
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: assign macro to the label in userform.... (2000 sr 1)

    ... only to understand how i can use Class?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: assign macro to the label in userform.... (2000 sr 1)

    You can set the BackColor (background color) or ForeColor (text color) property of the label in the code.

  7. #7
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: assign macro to the label in userform.... (2000 sr 1)

    ????????? similar....
    Private Sub Label1_Click()
    Label1.BackColor = &HC0FFC0
    Label_Click 1
    End Sub

  8. #8
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: assign macro to the label in userform.... (2000 sr 1)

    That is not very easy to explain.

    The way it works is shown here (for a bunch of controls on a worksheet)
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: assign macro to the label in userform.... (2000 sr 1)

    Do you want to set the same color for all labels, or a diferent color for each one?

  10. #10
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: assign macro to the label in userform.... (2000 sr 1)

    ... The condition to colorize label is valid for all label

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: assign macro to the label in userform.... (2000 sr 1)

    Place the line

    Me.Controls("Label" & n).BackColor = &HC0FFC0

    in the code for Label_Click.

  12. #12
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: assign macro to the label in userform.... (2000 sr 1)

    .. is possible to no permit a click on label if the the vlaue into column K of TABELLA is "0" or blank...
    Note: all textbox have a link on ControllSource

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: assign macro to the label in userform.... (2000 sr 1)

    Insert the following lines at the beginning of Label_Click (below the declarations Dim ... As ...):

    Dim strAG As String
    strAG = Right(Me.Controls("Label" & N).Caption, 4)
    If Val(Range("A:A").Find(What:=strAG, LookAt:=xlWhole).Offset(0, 10)) = 0 Then
    Beep
    Exit Sub
    End If

  14. #14
    Gold Lounger
    Join Date
    Jan 2004
    Location
    Italy
    Posts
    3,245
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: assign macro to the label in userform.... (2000 sr 1)

    ... Good..
    ...Then

    Beep or Msbox is the same?

  15. #15
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: assign macro to the label in userform.... (2000 sr 1)

    Beep only emits a sound. You can replace it with a MsgBox, or omit it. Whatever you prefer.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •