Forum Discussion
tomc72
Dec 01, 2022Brass Contributor
Today() or No Change if cell is already a date
COLUMN F G H I J K L M HEADING MATCH NO. DATE COMP. LEVEL PLAYER MATCH PTS PLAYER Pts COMPUTER Pts WINNER DATA 1 EXPERT Tom 5 7 2 Tom The above r...
- Dec 01, 2022Works like a dream. I had already allowed iterations but, and it´s a HUGE but, having copied your formula into my spreadsheet, I made an error with the row number! What a dummy!
Thank you so much for your help - and patience! 👍☺
HansVogelaar
Dec 01, 2022MVP
There are two ways to do this:
- Using iterative calculation.
- Using VBA code.
For iterative calculation:
- Select File > Options.
- Select Formulas.
- Tick the check box 'Enable iterative calculation'. You have to do this only once.
- In G2, enter the formula =IF(AND(K2:L2<>""),IF(G2<>"",G2,TODAY()),"")
- Fill down.
For a VBA solution:
- Right-click the sheet tab.
- Select 'View Code' from the context menu.
- Copy the code listed below into the worksheet module.
- Switch back to Excel.
- Save the workbook as a macro-enabled workbook (.xlsm).
- Make sure that you allow macros when you open the workbook.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Range
Dim r As Long
If Not Intersect(Range("K2:L" & Rows.Count), Target) Is Nothing Then
Application.ScreenUpdating = False
Application.EnableEvents = False
For Each rng In Intersect(Range("K2:L" & Rows.Count), Target)
r = rng.Row
If Range("K" & r).Value <> "" And Range("L" & rng.Row).Value <> "" Then
Range("G" & rng.Row).Value = Date
Else
Range("G" & rng.Row).ClearContents
End If
Next rng
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub- tomc72Dec 01, 2022Brass ContributorHi Hans. I´ve yet to try the code solution, but sad to say that you formula leaves G2 blank. Sorry!
I´ll try the VBA, tomorrow!
Thank you,
Tom- HansVogelaarDec 01, 2022MVP
The formula will enter a date in G2 if you enter something in both K2 and L2 (and if you have enabled iterative calculation)
See the attached demo workbook.
- tomc72Dec 01, 2022Brass ContributorWorks like a dream. I had already allowed iterations but, and it´s a HUGE but, having copied your formula into my spreadsheet, I made an error with the row number! What a dummy!
Thank you so much for your help - and patience! 👍☺