lundi 20 mars 2017

MS Excel - Run formula or save previous value based on random row selection

I have an Excel sheet for which I am selecting random rows based on bands of numbers. My initial goal was to select a row and save the time at which it was selected by the random number generator. However, due to recalculation and volatility of the rand() function, I had not been able to save selection times for all rows; only the current one.

  |  A   |     B       |      C      |  D  |E|F|  G   |  H   |     I    |
 -+------+-------------+-------------+-----+-+-+------+------+----------+
 1| Name | Time Save   | Time        | Blk | | | Rand | Item | Itm Name |
 2| A    | 0           | 0           | 0   | | | 727  | 8    | H        |
 3| B    | 0           | 0           | 100 |
 4| C    | 0           | 0           | 200 |
 5| D    | 0           | 0           | 300 |
 6| E    | 0           | 0           | 400 |
 7| F    | 0           | 0           | 500 |
 8| G    | 0           | 0           | 600 |
 9| H    | 42814.58888 | 42814.58888 | 700 |
10| I    | 0           | 0           | 800 |
11| J    | 0           | 0           | 900 |

  • G2: =RANDBETWEEN(0,E11+100)
  • H2: =MATCH(H2,$E2:E11,1)
  • I2: =INDEX($A$2:$A$27,$I$2)
  • Cx: =IF($Ax=$J$2,NOW(),0) where x is the row number
  • Bx: =VALUE(Cx) where x is the row number

Initially I thought that perhaps the value() function would simulate the manual Paste Special > Value command and effectively "freeze" the current value, but this was not working (no real surprise).

Before figuring out what I was doing wrong, I was able to type F9 repeatedly and successfully watch the floating-point timestamp jump around randomly in the C column and its value increase as expected. Additionally, this would be mirrored in the B column. However, previous times would not be saved and instead reset to 0.




Aucun commentaire:

Enregistrer un commentaire