Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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"

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading