On double click change colour of Named Range

fastrack

New Member
Joined
Jun 1, 2020
Messages
5
Office Version
  1. 2019
Platform
  1. Windows
I require a macro so that once double clicked a selected range is then coloured green

Can you guys help please
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Double clicking on a cell brings Excel in input mode so that would be a real challenge. Imo it's not possible, so you have to search for another way to launch your macro. To change color use this, code is self explanatory.
VBA Code:
Sub Example()
    Const cGreen As Long = 2779203

    Selection.Interior.Color = cGreen
    Selection.Font.Color = cGreen

End Sub
 
Upvote 0
sorry maybe I should of been clearer I have named ranges Ie run 1 run2 I want the user to be able to click to change the run (named range) as green maybe right click would be fine
 
Upvote 0
VBA Code:
Range("NameOfYourRange").Font.Color = 1234567
You might consider using the macro recorder in order to obtain the color number of the kind of green you like the most.
 
Upvote 0
You can use a double click event, something like
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   Select Case Target.Address(0, 0)
      Case "A1"
         Range("Run_1").Interior.Color = 45678
         Cancel = True
      Case "B1"
         Range("Run_2").Interior.Color = 45678
         Cancel = True
   End Select
End Sub
 
Upvote 0
Hmm thats not working

this code works but I dont know how to link to once clicked it highlights the named block


VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Cancel = True
    Target.Interior.Color = vbGreen
End Sub
 
Upvote 0
Which cells do you want to click on & what are the named ranges they should colour?
 
Upvote 0

Forum statistics

Threads
1,214,976
Messages
6,122,539
Members
449,088
Latest member
RandomExceller01

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