Delete some cells when using doubleclick in column B

Simon Robert

New Member
Joined
Jan 31, 2023
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi

I already have the following formula in my worksheet that add the date when the user doubleclick in the column B

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Row >= 5 And Target.Row <= 500 And Target.Column = 2 Then ActiveCell.Value = Time + Date
End Sub

I would like to add something to clear the content of cells C, D, E, F of the same row when the user doubleclick in the column B.

Thanks
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Try this

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column = 2 Then
Target.EntireRow.Range("C:F").ClearContents
End If
End Sub
 
Upvote 0
Hi Andyka, thanks for your help.

Do you mean that the new formula should be the following? It seams that Excel do not like the Target.EntireRow.Range("C:F").ClearContents.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Row >= 5 And Target.Row <= 500 And Target.Column = 2 Then ActiveCell.Value = Time + Date
Target.EntireRow.Range("C:F").ClearContents

End Sub
 
Upvote 0
How about
Excel Formula:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   If Target.Row >= 5 And Target.Row <= 500 And Target.Column = 2 Then
      Target.Value = Time + Date
      intersect(Target.Row, Range("C:F")).ClearContents
   End If
End Sub
 
Upvote 0
How about
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   If Target.Row >= 5 And Target.Row <= 500 And Target.Column = 2 Then
      Target.Value = Time + Date
      Intersect(Target.EntireRow, Range("C:F")).ClearContents
      Cancel = True
   End If
End Sub
 
Upvote 1
Solution
How about
VBA Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
   If Target.Row >= 5 And Target.Row <= 500 And Target.Column = 2 Then
      Target.Value = Time + Date
      Intersect(Target.EntireRow, Range("C:F")).ClearContents
      Cancel = True
   End If
End Sub
This is exactly what I needed. Thanks
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,301
Members
449,078
Latest member
nonnakkong

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