Giving a cell the colour red with hotkey Alt/R and giving a cell the colour green with hotkey Alt/G

HarrySiers

Board Regular
Joined
May 27, 2015
Messages
61
Dear forumers,

I would like to give an Excel cell a red colour with hotkey Alt/R and I would like to give an Excel cell a green colour with hotkey Alt/G. Subquestion: is it possible to sort cells on the basis of a colour (red/green)?

Any solution?

Thank you in advance!
Harry
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Run the SetKeys procedure below to set the keyboard shortcuts. You can sort cell by colour using Home --> Editing --> Sort & Filter --> Custom Sort.

Code:
Sub SetKeys()

  With Application
    .OnKey "%r", "ColorRed"
    .OnKey "%g", "ColorGreen"
  End With

End Sub

Sub ColorRed()
    
  If TypeOf Selection Is Range Then
    Selection.Interior.Color = vbRed
  End If
  
End Sub

Sub ColorGreen()
    
  If TypeOf Selection Is Range Then
    Selection.Interior.Color = vbGreen
  End If
  
End Sub
 
Upvote 0
Run the SetKeys procedure below to set the keyboard shortcuts. You can sort cell by colour using Home --> Editing --> Sort & Filter --> Custom Sort.

Code:
Sub SetKeys()

  With Application
    .OnKey "%r", "ColorRed"
    .OnKey "%g", "ColorGreen"
  End With

End Sub

Sub ColorRed()
    
  If TypeOf Selection Is Range Then
    Selection.Interior.Color = vbRed
  End If
  
End Sub

Sub ColorGreen()
    
  If TypeOf Selection Is Range Then
    Selection.Interior.Color = vbGreen
  End If
  
End Sub

Hello gpeacock,

Thanks a lot for your fast reply! I am a layman with Excel and I am sure I am doing something wrong here because the following happens when I run the macro with F5 (I have not assigned or changed anything, I have only run the macro with F5 in a sheet that contains a word in B1 and a word in B2, see below):

I have a cell B1 with the word Hello and a cell B2 with the word Goodbye. What I would like to do is give the (empty) cell A1 the colour Green with hotkey Alt/G and to give the (empty) cell A2 the colour Red with Alt/R - I would like to do this manually, based on the information in cells B1 and B2. If the cell A1 should have the colour green, because for instance cell B1 contains the word Hello, I would like to make cell A1 green, if the cell A2 should have the colour red, because for instance cell B2 contains the word Goodbye, I would like to make cell A2 red.

Thank you in advance for your help, I appreciate it!

Regards,
Harry
 
Upvote 0
PS: When I ran the macro cell A1 became green, but when I tried to use hotkey Alt/R in cell A2 nothing happened. In addition, I would like to be able to toggle between green and red in cell A1 (by using Alt/G and Alt/R respectively) if for instance I change the content in B1 from Hello to Goodbye or back to Hello.
 
Upvote 0

Forum statistics

Threads
1,203,171
Messages
6,053,878
Members
444,692
Latest member
Queendom

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