Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
How to stop Excel from updating a cell?
How do I get excel to not insert new data into a cell? To just leave a cell alone unless certain criteria is met?
So for example
A1 = =RANDBETWEEN(1,9)
B1 = IF(A1=5,A1,<leave it as is>)
I want to hit refresh until B1 displays “5” (because the conditions were met) and then let it keep that “5” after I hit refresh again multiple times and the condition are no longer true.
And having a cell reference itself and limiting the number of iterations doesn't help in this case.
1 Answer
- garbo7441Lv 72 years ago
As I understand it, once B1 displays '5', you don't want it to change again, until perhaps you delete the entry in B1. If so, you will need to utilize VBA to do as you wish. This method does not fire on 'Refresh', but upon double clicking any cell.
Copy this event handler to the clipboard (highlight the entire handler, right click inside the highlighted area, and 'Copy').
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
On Error GoTo errhandler
ActiveWorkbook.RefreshAll
Application.EnableEvents = False
Range("A1").Formula = "=RANDBETWEEN(1,9)"
If Range("A1").Value = 5 Then
Range("B1").Value = 5
End If
errhandler:
Application.EnableEvents = True
Target.Offset(1).Select
End Sub
Right click the sheet tab at the bottom of your worksheet and select 'View Code'.
Paste the event handler into the white editing area to the right (right click inside the area and Paste).
Close the VBE (red button - top right).
Save the workbook as an Excel Macro-Enabled Workbook to retain this functionality in the future. Archive the original workbook to avoid confusion as to which to use.
To enter a random number between 1 and 9, double click any cell. Each double click triggers the RANDBETWEEN function in A1. Once B1 displays '5', it will not change again until you delete the entry in B1.
Note: Double clicking will initiate a 'Refresh All' action on the active workbook before processing the RANDBETWEEN function.
Advise if I have misinterpreted you goal.