Date static

Colleen45

Active Member
Joined
Jul 22, 2007
Messages
495
I would like to have the date inserted ( b1) whenever the value in cell a1 exceeds 0, the date must not change when i open the workbook a few days later.
I am using this in a Library situation, where excel needs to remember the date the book was issued. thus I need to apply this to the entire column.for each item that gets loaned out. (and obviously remove the date when the value goes back to 0
I realize that some VBA code is required, as there is no worksheet function.
As a second part to this question, could i use the same code in a second private sub statement on the same worksheet.
This time when ever the value in cell c1 (for example) exceeds 0 (new card no) it needs to insert the date in d1 (date joining) and again not change when the workbook is reopened (again i need to apply it to the entire column)
sorry for the long explanation
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
This code will do both. Right click the sheet tab and select View Code. Copy and paste in the following. Then close the code window and try entering values in columns A and C.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If Target.Column = 1 Or Target.Column = 3 Then
    If Target.Value > 0 Then
        Target.Offset(0, 1).Value = Date
    Else
        Target.Offset(0, 1).Value = ""
    End If
End If
End Sub

Edit: amended code!
 
Upvote 0
Thanks for your e-mail. For the columns that you specified, here is the code:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
' Add current date
' Entry in column A (1) add date in H (8)
' Entry in column R (18) add date in T (20)
If Target.Count > 1 Then Exit Sub
If Target.Column = 1 Then
    If Target.Value > 0 Then
        Target.Offset(0, 7).Value = Date
    Else
        Target.Offset(0, 7).Value = ""
    End If
ElseIf Target.Column = 18 Then
    If Target.Value > 0 Then
        Target.Offset(0, 2).Value = Date
    Else
        Target.Offset(0, 2).Value = ""
    End If
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,051
Messages
6,122,872
Members
449,097
Latest member
dbomb1414

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