Formatting Cell and Returning to previous state

SamFunzie

New Member
Joined
Oct 4, 2021
Messages
10
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I think this is simple, but I just cannot seem to get it... new(ish) to Excel VBA

I have a cell, when double clicked that cell and the one to its left get altered formatting wise... that works...
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Cancel = True
Target.Interior.Color = vbYellow
With Target.Offset(0, -1)
.Interior.Color = vbRed
.Font.Color = vbWhite
.Font.Strikethrough = True
End With
End Sub

But now, if I want the cells to be cleared of the formatting, I would like to be done by using the "ESCAPE" key... this is NOT working....
VBA Code:
Private Sub EscapetoRepair()
Application.OnKey "{ESC}", Procedure:="RepairCell"
End Sub

Sub RepairCell()
ActiveCell.Select
ActiveCell.Interior.Color = xlNone
ActiveCell.Value = nil
ActiveCell.Offset(0, -1).Select
With ActiveCell
.Interior.Color = xlNone
.Font.Color = vbBlack
.Font.Strikethrough = False
End With
End Sub

Would someone be kind enough to point me in the right direction...

Just a note... I had it working with a right click event, but right clicking caused some unforeseen issues therefore I want to assign it to the "ESCAPE" key...

Also, I have a follow-up "bonus" question for the same thing, but perhaps that should be a separate thread...

Thanks,

SF
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Thanks anyway.... found out the issue.... placement of the three sections was the key...

Thank you again....
 
Upvote 0
Solution

Forum statistics

Threads
1,214,414
Messages
6,119,375
Members
448,888
Latest member
Arle8907

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