Assistance with macro

blewth

New Member
Joined
Aug 9, 2016
Messages
15
Hi

I am trying to make a Macro, whereby I hit Ctrl Shift G and my text or number will turn green.

My macro is below:

-------

' Keyboard Shortcut: Ctrl+Shift+J
'
With Selection.Font
.ColorIndex = 4
End With
End Sub

------

It does not seem to work however? Nothing happens. I have other macros in the same format structure for blue, red, etc. But nothing seems to happen when I try do green?

Thanks
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
It needs to look like this:

Code:
Sub Color_Me()
'Modified  10/30/2018  11:22:06 PM  EDT
With Selection.Font
.ColorIndex = 4
End With
End Sub
 
Upvote 0
Forgive me if I am wrong, but does it not like this already?

Mine...

With Selection.Font
.ColorIndex = 4
End With
End Sub

-------

Yours..

With Selection.Font
.ColorIndex = 4
End With
End Sub
Forgive my ignorance. I assume you dont mean the 2 lines above it as well?

Thanks
 
Upvote 0
.
Paste this in the Sheet Module :

Code:
Option Explicit


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Color_Me
End Sub

Paste your macro in a regular module.
 
Upvote 0
Hi, blewth
Your code should work. Maybe the issue is in keyboard shortcut. Do you use Ctrl+Shift+G or Ctrl+Shift+J?
 
Upvote 0
I am sorry could you break down the code for me? So how does the above work with the below?

With Selection.Font
.ColorIndex = 4
End With
End Sub
 
Upvote 0
You want the shortcuts hardcoded? This works for me:

Code:
Private Sub Workbook_Open()
Application.OnKey "^+j", "ChangeColor"
End Sub


Sub ChangeColor()
With Selection.Font
    .ColorIndex = 4
End With
End Sub

Edit: Application.OnKey "^+j", "ChangeColor" that line should go in the WorkBook_Open event
 
Last edited:
Upvote 0
I see no:
Sub Color_Me()


Forgive me if I am wrong, but does it not like this already?

Mine...

With Selection.Font
.ColorIndex = 4
End With
End Sub

-------

Yours..

With Selection.Font
.ColorIndex = 4
End With
End Sub
Forgive my ignorance. I assume you dont mean the 2 lines above it as well?

Thanks
 
Upvote 0
The script worked for me. You need some text in the cell to see the color

All scripts must start with

Sub Color_Me()

and end with

End Sub

Your script shown here had no start like:

Sub Color_Me()
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,252
Members
452,623
Latest member
Techenthusiast

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