Insert Timestamp when cell value = 1

RLJ

Active Member
Joined
Mar 15, 2011
Messages
417
Office Version
  1. 365
Platform
  1. Windows
Hello,

I need vba to insert a timestamp into the cell in column G when the cell in column B =1. Conversely, if there is a 1 in the cell in Column B and it is removed, then it removes the timestamp in Column G.

Ex: B8 = 1, then G8 will have the timestamp.

My data is in a table called ToDoList and column B is Done and column G is Timestamp.

Thank you!
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
How exactly is the value in column B being updated?
Is it being updated manually, or is it a formula?
If a formula, what is the formula?
 
Upvote 0
How exactly is the value in column B being updated?
Is it being updated manually, or is it a formula?
If a formula, what is the formula?
It is being updated manually by user.
 
Upvote 0
Excellent!

Right-click on the sheet name at the bottom of the screen, select “View Code”, and enter the following VBA code in the VB Editor that pops open:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.CountLarge > 1 Then Exit Sub
    
'   Only run if column B is updated
    If Target.Column = 2 Then
'       Check to see if column B set to 1
        If Target.Value = 1 Then
'           Add date/time stamp to column G
            Target.Offset(0, 5).Value = Now()
        End If
'       Check to see if column B is blank and column G has a date/time stamp
        If Target.Value = "" And Target.Offset(0, 5).Value > 0 Then
'           Remove date/time stamp from column G
            Target.Offset(0, 5).ClearContents
        End If
    End If

End Sub

The code will run automatically as you make manual updates to column B.
 
Upvote 0
Solution
Excellent!

Right-click on the sheet name at the bottom of the screen, select “View Code”, and enter the following VBA code in the VB Editor that pops open:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    If Target.CountLarge > 1 Then Exit Sub
   
'   Only run if column B is updated
    If Target.Column = 2 Then
'       Check to see if column B set to 1
        If Target.Value = 1 Then
'           Add date/time stamp to column G
            Target.Offset(0, 5).Value = Now()
        End If
'       Check to see if column B is blank and column G has a date/time stamp
        If Target.Value = "" And Target.Offset(0, 5).Value > 0 Then
'           Remove date/time stamp from column G
            Target.Offset(0, 5).ClearContents
        End If
    End If

End Sub

The code will run automatically as you make manual updates to column B.
Most Excellent. It works perfectly. Thanks
 
Upvote 0

Forum statistics

Threads
1,215,155
Messages
6,123,331
Members
449,098
Latest member
thnirmitha

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