ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Double-click entry (https://www.excelbanter.com/excel-programming/290043-double-click-entry.html)

RJH

Double-click entry
 
Rob gave me some of the code below. I've modified it to include 2 columns
instead of 1 and a message box. It works just fine but I'm sure there's a
better way to write it then to double up the code. I've tried a few things
with no luck. How would I trim this down?

Thanks!

Bob Howard

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
If Target.Column = 1 Then
If Target.Cells 0 Then GoTo Line1 Else
Target.Value = Format(Now(), "mm-dd-yyyy")
Target.Offset(0, 1).Select
Exit Sub

Line1:
MsgBox "This cell contains a date, choose another cell", vbCritical
Target.Offset(0, 1).Select
End If

If Target.Column = 11 Then
If Target.Cells 0 Then GoTo Line2 Else
Target.Value = Format(Now(), "mm-dd-yyyy")
Target.Offset(0, 1).Select
Exit Sub

Line2:
MsgBox "This cell contains a date, choose another cell", vbCritical
Target.Offset(0, 1).Select
End If

End Sub



mudraker[_140_]

Double-click entry
 
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel A
Boolean)
Select Case Target.Column
Case 1, 11
If Target.Cells 0 Then
MsgBox "This cell contains a date, choose another cell", vbCritical
Target.Offset(0, 1).Select
Else
Target.Value = Format(Now(), "mm-dd-yyyy")
Target.Offset(0, 1).Select
End If
End Su

--
Message posted from http://www.ExcelForum.com


RJH

Double-click entry
 
I thought about the select case function but couldn't construct it and make
it work. I also couldn't get the "If, then, else" statement to work, that's
why I used the 'goto'.
It works geat!
Thanks!

Bob Howard


"mudraker " wrote in message
...
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
Select Case Target.Column
Case 1, 11
If Target.Cells 0 Then
MsgBox "This cell contains a date, choose another cell", vbCritical
Target.Offset(0, 1).Select
Else
Target.Value = Format(Now(), "mm-dd-yyyy")
Target.Offset(0, 1).Select
End If
End Sub


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 09:30 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com