VBA Code to clear contents Not formulas on spreadsheet

Malcolm torishi

Board Regular
Joined
Apr 26, 2013
Messages
219
Hi can anyone help please, I have the following code that clear the contents as well as the formulas on my spreadsheet. Can any tell me please how not to clear the formulas . Thanks
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Modified 6/18/2019 3:09 PM EDT
If Target.Column = 28 And Target.Row > 1 Then
Cancel = True
Dim Lastrow As Long
Lastrow = Sheets(3).Cells(Rows.Count, "A").End(xlUp).Row + 1
Target.Offset(, -25).Resize(, 1).Copy Sheets(3).Cells(Lastrow, 1)
Target.Offset(, -25).Resize(, 25).ClearContents
End If

If Target.Column = 1 Then
Cancel = True
Target.Font.Name = "Wingdings"
If Target.Value = "" Then
Target.Value = "ü"
Else
Target.Value = ""
End If
End If

End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try
Code:
Target.Offset(, -25).Resize(, 25)[COLOR=#ff0000].SpecialCells(xlConstants)[/COLOR].ClearContents
 
Upvote 0
On other question if I may, this code deletes the contents from say column AA back 25 columns, if I want to delete say 3 other columns forward on say column AG, AH & AI is that something that can be added in the code above. Thank
you again
 
Upvote 0
Just add this below that line
Code:
   Range("AG" & Target.Row).Resize(, 3).ClearContents
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

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