Label back color change when double click.

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,186
Office Version
  1. 2013
Platform
  1. Windows
Hello,
Can I get help with the code given below.
I'm trying to change back color of label.:)
Thanks..


Code:
Private Sub Label1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)

    With Application
    Me.Label1.BackColor = 15773696
    End With


End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
6,977
Office Version
  1. 365
Platform
  1. Windows
Your code works for both..
- a label on a userform
- an active-x label on a worksheet

The code needs to be in the userform or sheet module as relevant
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
72,989
Office Version
  1. 365
Platform
  1. Windows
You're code works for me, in what way isn't it working for you?
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
37,866
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Hello,
Can I get help with the code given below.
I'm trying to change back color of label.:)
Thanks..
Code:
Private Sub Label1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
    With Application
    Me.Label1.BackColor = 15773696
    End With
End Sub
As others have said, the code you posted works fine. Actually, the With..EndWith statements and Me qualifier are not needed as this works the same way...
Code:
Private Sub Label1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
  Label1.BackColor = 15773696
End Sub
As to your problem... is it that you wanted the code to toggle the color on and off as you repeatedly double clicked the Label? If so, give this code a try...
Code:
Private Sub Label1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
  If Label1.BackColor = -2147483633 Then
    Label1.BackColor = 15773696
  Else
    Label1.BackColor = -2147483633
  End If
End Sub
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,477
Messages
5,831,904
Members
430,090
Latest member
bjonesh2o

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