PDA

View Full Version : Solved: Excel on double click event help



ncasper
08-10-2010, 04:27 PM
I found code that will allow me to doubleclick on any cell within a predefined column (D) and will set the value to "No" if I doubleclick. I am looking for it to do two other things.

1. If I double click on a cell in column D and it changes it to "No" I would also like it to delete the value in the same row in the column to the left (C).

2. If I double click on a cell in the column (D) and it already has the value "No" I would like it to erase the contents of the cell.

Here's the code:

Private Sub Worksheet_BeforeDoubleClick( _
ByVal Target As Range, Cancel As Boolean)
Dim rInt As Range
Dim rCell As Range
Set rInt = Intersect(Target, Range("D3:D200"))
If Not rInt Is Nothing Then
For Each rCell In rInt
rCell.Value = "No"
Next
End If
Set rInt = Nothing
Set rCell = Nothing
Cancel = True
End Sub

Is this easily doable? (Excel 2007/Windows).

I appreciate any help anyone can offer.

Thanks.

mbarron
08-10-2010, 08:14 PM
Try this:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("D3:d200")) Is Nothing Then
If Target <> "No" Then
Target = "No"
Target.Offset(0, -1).ClearContents
Else
Target.ClearContents
End If
End If
Cancel = True
End Sub

ncasper
08-11-2010, 08:06 AM
Thank you very much for your help.

Your suggestion worked perfectly.