Double click to return original value

whppat

New Member
Joined
Dec 1, 2022
Messages
1
Office Version
  1. 365
Platform
  1. Windows
Hi. Can anyone help with the code to return the cell value to what it was before double-clicking on it, like back-and-forth between the same two values only? Here's my code currently. If my cell value is A and I double-click, I get my B value. What I'd like to do is double-click again and go back to A, and again to B...

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("H2:h53")) Is Nothing Then
Application.EnableEvents = False
If ActiveCell.Value = "A" Then ActiveCell.Value = "B"
End If
Cancel = True
Application.EnableEvents = True
End Sub

Tks
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Hi & welcome to MrExcel.
How about
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("H2:h53")) Is Nothing Then
Application.EnableEvents = False
If Target.Value = "A" Then
   Target.Value = "B"
Else
   Target.Value = "A"
End If
End If
Cancel = True
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,221
Messages
6,123,701
Members
449,117
Latest member
Aaagu

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