Double Click to enter User ID

monk22

New Member
Joined
Jul 31, 2007
Messages
12
Guys, i have some code that allows my users to enter their user ID on double clicking. The worksheet code below shows how on double clicking into Colum 3 (If Target.Column = 3 Then) then the user ID will appear. Q: How do i get the code to work in Columns 3, 5 and 7 but not those inbetween?! I tried using "or" but it allowed the ID to be entered into all columns! i.e. 3,4,5,6 and 7 which is not what I require. In short I need the ID to appear on double clik into every other column. Thanks. See below for code:



Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Dim user As String
'This refers to the function ReturnUserName, which takes the name from the NT environment

If Target.Column = 3 Then
Target = ReturnUserName
Cancel = True
End If

End Sub



Many Thnaks
Monk22
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi. Sorry about that :oops: - it works in XL 2007 but not in XL 2000.

Try this

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column Mod 2 = 1 And Target.Row Mod 2 = 1 Then
    Target.Value = Environ("username")
    Cancel = True
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,579
Messages
6,125,646
Members
449,245
Latest member
PatrickL

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