Listing words in excel using VBA program

ESath

New Member
Joined
Apr 19, 2010
Messages
12
I need to make 2 lists:

1) With a list of 25 random people, i need to make each one a random male or female (designated by M or F). So in A2:A26 I have the numbers 1-25 designating a person but in B2:B26 I need a function that when the macro is run, it will randomly generate M and F for each.

This is what I had for this one but it lists all letters F through M:

Sub Gender()
Dim RandomRange As Range, cell As Range
Set RandomRange = Range("c2:c26")
For Each cell In RandomRange
cell.Formula = "=CHAR(RANDbetween(70,77))"
Next
RandomRange.Value = RandomRange.Value
End Sub

2) For C2:C26, I need to reference each person as smoker and non-smoker. Basically the same concept as before except instead of M and F, I need the full words "smoker" and "non-smoker.

Thanks in advance!
 
Last edited:

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Change the formula to;
Code:
Sub Gender()
Dim RandomRange As Range, cell As Range
Set RandomRange = Range("c2:c26")
For Each cell In RandomRange
cell.Formula = "=INDEX({""F"",""M""},INT(RAND()*2+1))"
Next
RandomRange.Value = RandomRange.Value
End Sub

Note: Formula adapted from one of Barry Houdini's posts.

HTH
Colin
 
Upvote 0

Forum statistics

Threads
1,223,237
Messages
6,170,930
Members
452,367
Latest member
TePunaBloke

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