Values entered on double-click

Harry_T

New Member
Joined
Sep 27, 2017
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

I'm trying to figure out how to add two separate values with double clicking in cells within a specified range. I found a string of vba that helps me do one of the values that I'm looking to populate but I know that you cannot enter two of these strings into the background of a worksheet in vba. I'm trying to see if there's a way to get the code entered that it can enter the date in a set column/range and enter the username in another. Currently I can only get one or the other. Thanks for the help in advance!

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("b1:B10")) Is Nothing Then
Cancel = True
Target.Formula = Date
End If
End Sub

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("b1:B10")) Is Nothing Then
Cancel = True
Target.value = environ("username")
End If
End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("b1:B10")) Is Nothing Then
Cancel = True
Target.Formula = Date
Target.Offset(, 1) = Environ("username")
End If
End Sub
In place of both your codes
 
Upvote 0
Try
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Not Intersect(Target, Range("b1:B10")) Is Nothing Then
Cancel = True
[B][COLOR="#FF0000"]Target.Formula = Date
Target.Offset(, 1) = Environ("username")[/COLOR][/B]
End If
End Sub
In place of both your codes
Just a "for your information" comment for the readers of this thread: The above two highlighted lines of code can be replaced by this single line of code...

Target.Resize(, 2) = Array(Date, Environ("username"))
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,272
Members
449,075
Latest member
staticfluids

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