Add one of 2 values to a cell randomly

Let’s say I have a cell "A2" and I want to locate on this cell either the initials BA or CF (I want to do this randomly)

How would I able to do that?

So far I have
Worksheets("Sheet1").range("A2").value = "BA"

but I don’t know what I can do so that from now on it either adds BA or CF randomly.

>Solution :

You can use Rnd() (which produces a random value between 0 and 1)

Worksheets("Sheet1").range("A2").value = IIf(Rnd()>0.5, "BA", "CF")

Leave a Reply