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
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,651
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
 

Forum statistics

Threads
1,082,557
Messages
5,366,304
Members
400,882
Latest member
zaldy_a

Some videos you may like

This Week's Hot Topics

Top