Time stamp cells on single mouse click

SJV9

New Member
Joined
Jul 21, 2011
Messages
22
Hi everyone!

Can someone help me on how I could get a time stamp on column G each time cells on column B is clicked?

I tried inserting both commandbuttons or labels and set them to invisible so the text underneath is the thing to be seen. I got it to stamp the time on a single click alright however I would also want to be able to select the value on the cell underneath the label/button.

:confused:
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Right click the sheet tab, View Code, and paste:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Dim iRange As Range
  If Target.Cells.Count <> 1 Then Exit Sub
  Set iRange = Intersect(Target, Range("B:B"))
  If iRange Is Nothing Then Exit Sub
  Application.EnableEvents = False
  Range("G" & Target.Row).Value = Now()
  Application.EnableEvents = True
End Sub
 
Upvote 0
Wow Kenneth that was quick! Is this static time stamp? I wouldnt want it to change each day I open the file.

Also, I need it to do the same on column R when column C is clicked.


I appreciate your quick response and efficiency!
 
Upvote 0
Now() is the current date and time.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Dim iRange As Range, dt As Date
  dt = Now()
  If Target.Cells.Count <> 1 Then Exit Sub
  Set iRange = Intersect(Target, Range("B:B"))
  If iRange Is Nothing Then Exit Sub
  Application.EnableEvents = False
  Range("G" & Target.Row).Value = dt
  Range("R" & Target.Row).Value = dt
  Columns("G:G").AutoFit
  Columns("R:R").AutoFit
  Application.EnableEvents = True
End Sub
 
Upvote 0
It time stamps on both columns G and R each time column B is clicked. Can you tweak it a little bit so it becomes:

- time stamp on G when B i clicked
- time stamp on R when C is clicked

Also, I enabled iterative calculation and set it to 1 but it still makes the time stamps dynamic...
 
Upvote 0
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Dim iRange As Range
  If Target.Cells.Count <> 1 Then Exit Sub
  Set iRange = Intersect(Target, Range("B:C"))
  If iRange Is Nothing Then Exit Sub
  Application.EnableEvents = False
  Select Case Target.Column
    Case 2
      Range("G" & Target.Row).Value = Now()
        Columns("G:G").AutoFit
    Case 3
      Range("R" & Target.Row).Value = Now()
      Columns("R:R").AutoFit
  End Select
  Application.EnableEvents = True
End Sub
 
Upvote 0
This works for me. Thank you so much Kenneth!!! You're a genius! :pray:

Have a great day!

:)
 
Upvote 0
I recommend reading this article about crossposting: http://www.excelguru.ca/node/7

If you don't want the cells to update if they have a value:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  Dim iRange As Range
  If Target.Cells.Count <> 1 Then Exit Sub
  Set iRange = Intersect(Target, Range("B:C"))
  If iRange Is Nothing Then Exit Sub
  Application.EnableEvents = False
  Select Case True
    Case Target.Column = 2 And IsEmpty(Range("G" & Target.Row))
      Range("G" & Target.Row).Value = Now()
        Columns("G:G").AutoFit
    Case Target.Column = 3 And IsEmpty(Range("R" & Target.Row))
      Range("R" & Target.Row).Value = Now()
      Columns("R:R").AutoFit
  End Select
  Application.EnableEvents = True
End Sub
 
Upvote 0
Hi Kenneth, thanks for the tip!

In relation to your vb formula, is it possible if can we set it to apply only to cells which have values so that there should be no time stamp coming from blank cells?
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,626
Members
452,933
Latest member
patv

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