IF cell A1=A, after 15 minutes, automatically change into B

Copper Contributor

I need a formula to change value from A to B after 15 minutes of inserting A. 
The ChatGPT suggested me this formula but it did not work 

=IF(A1="A",IF(NOW()>=A1+TIME(0,15,0),"B",A1),"")

4 Replies
Lately, the AI suggested to run appscript:
function onEdit(e) {
if (e && e.range) {
var sheet = e.range.getSheet();
var columnE = e.range.getColumn() == 5;
var valueA = e.value == "1";

if (sheet.getName() == "DIEUPHOI" && columnE && valueA) {
var range = sheet.getRange(e.range.getRow(), columnE);
var timer = Utilities.formatDate(new Date(), "GMT+7", "HH:mm:ss");
range.setValue("2");
SpreadsheetApp.flush();
ScriptApp.newTrigger("resetCell")
.timeBased()
.after(1 * 60 * 1000);
}
}
}
function resetCell() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("DIEUPHOI");
var range = sheet.getRange("E:E").getValues();
range.forEach(function(row, index) {
if (row[0] == "2") {
var timeString = row[0].split("-")[1].trim();
var savedTime = new Date();
savedTime.setHours(timeString.split(":")[0], timeString.split(":")[1], timeString.split(":")[2]);
var currentTime = new Date();
if (currentTime - savedTime > 1 * 60 * 1000) {
sheet.getRange(index + 1, 5).setValue("2");
}
}
});
}

But in the test, it did not work either.

@ViApril6 

I ask my AI the same question :), here the result…

Excel formulas are recalculated when the workbook is opened or when the data in the workbook changes. This means that a formula cannot automatically update a cell value after a specific amount of time has passed without any changes to the data in the workbook.

 

One way to achieve a similar result is to use a combination of a formula and a VBA (Visual Basic for Applications) macro. The formula can check if the value in cell A1 is "A" and if the current time is greater than or equal to the time when "A" was entered plus 15 minutes. The VBA macro can be set to run automatically at regular intervals (e.g., every minute) to recalculate the formula and update the cell value if necessary.

 

Here's an example of how this can be done:

 

  1. In cell B1, enter the following formula: `=IF(A1="A",IF(NOW()>=C1+TIME(0,15,0),"B",A1),"")`
  2. In cell C1, enter the following formula: `=IF(A1<>"",IF(C1="",NOW(),C1),"")`
  3. Press "Alt+F11" to open the Visual Basic editor.
  4. In the Project Explorer, double-click on "ThisWorkbook" to open the code window.
  5. In the code window, enter the following VBA code:

 

Private Sub Workbook_Open()

    Application.OnTime Now + TimeValue("00:01:00"), "UpdateValue"

End Sub

 

 

  1. In the Project Explorer, right-click on "ThisWorkbook" and select "Insert" > "Module".
  2. In the code window for the new module, enter the following VBA code:

 

Sub UpdateValue()

    Sheet1.Range("B1").Calculate

    Application.OnTime Now + TimeValue("00:01:00"), "UpdateValue"

End Sub

 

 

  1. Save the workbook as a macro-enabled workbook (with the ".xlsm" file extension).

 

Now, when you open the workbook and enter "A" in cell A1, the value in cell B1 will automatically change to "B" after 15 minutes.

 

Please note that this is just an example and you may need to adjust the cell references and time intervals to fit your specific needs. Also, keep in mind that using macros can pose a security risk and you should only use macros from trusted sources.

 

Haven't tried it myself, but should work so far and at first glance :).

 

I hope this helps!

Thank you anyway, but in Google Sheets, we do not have VBA (instead is AppScript) but I cannot find a way to follow from step 5 so on
Google Sheets, unfortunately I can't help there, my knowledge is limited.
If I may recommend, always include accurate information about your digital environment at the beginning. digitsle environment such as Excel version, operating system, storage medium, etc. This would help you to get faster and more accurate solution suggestion and on the other hand would save much time which will benefit other users.

Thank you for your understanding