Whats wrong with my code?

siasarma

New Member
Joined
Sep 20, 2008
Messages
46
I am trying to use a code where I can double click in cell B, C, D and E and have it enter the time from my computer. It works ok...but I was wondering if there was a way that I can only limit it to a certain number of cells in those columns. For instance I only want it in cells B7:B13. and then B20:B26. Is there anything else I can do???

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column > 5 Then Exit Sub 'set for column "B7:B13""B:20:B26""C7:C13""C20:C26""D7:D13""D20:D26""E7:E13""E20:E26"Adjust as needed
Target = Time 'Change to Now for Time
Cancel = True
'
' Keyboard Shortcut: Ctrl+Shift+S
'
ActiveWorkbook.Save

End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Intersect(Target, Range("B7:B13, B20:B26, C7:C13, C20:C26, D7:D13, D20:D26, E7:E13,E20:E26")) Is Nothing Then Exit Sub
Target.Value = Now 'Change to Now for Time
Cancel = True
'
' Keyboard Shortcut: Ctrl+Shift+S
'
ActiveWorkbook.Save

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,550
Messages
6,114,265
Members
448,558
Latest member
aivin

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