Change a number to text.

Sjakalen

New Member
Joined
Jun 7, 2012
Messages
2
Hi all.

I am writing a code which should generate the letters m or f (male/female)
in A2:A21. I am able to generate random 1's and 0´s, but now i can't convert them to the letters. Below is the code (note: i know it might not be the smartest way to do this, but to keep the same datastructure which i have in previous coding, i would like to keep it this way)

****
t = 1

Range("A1").Select

Low = 1
High = 2

Do

t = (t + 1)
ActiveCell.Offset(1, 0).Select
value= Int((High - Low + 1) * Rnd() + Low)
ActiveCell.Value = value
Loop Until t = 20

****

All help appreciated.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Sjakalen,

One way...
Code:
    t = 1
    
    Low = 1
    High = 2
    
    Do
        t = t + 1
        Value = Choose(Int((High - Low + 1) * Rnd() + Low), "Male", "Female")
        Cells(t, "A").Value = Value
    Loop Until t = 20
 
Upvote 0

Forum statistics

Threads
1,203,096
Messages
6,053,516
Members
444,669
Latest member
Renarian

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top