Pick letter randomly

Temporary-Failure

Board Regular
Joined
Jul 16, 2010
Messages
140
I want code which will choose randomly T, D or S letter. How to do it?

edit, well this is one way...

Code:
    kerroin1 = Int((3 - 1 + 1) * Rnd + 1)
        Select Case kerroin1
            Case 1
                etuliite1 = "S"
            Case 2
                etuliite1 = "D"
            Case 3
                etuliite1 = "T"
        End Select
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
I am not a code guy, so pre-apologies. However, here is a concept that you probably can get to work.

Have your code choose a random number from 1 to 3, then right If statements to associate the number with a letter.

RandNumber = RandBetween (1,3)
RandLetter =

if RandNumber = 1, "S"
Else
if RandNumber = 2, "D"
Else
"T"
Endif

Then do your cases. If fact, unless there is a reason, why not just use the number without associating to a letter?

Again, no code guy here, but hope this spurs some thought.

Jeff
 
Upvote 0
Maybe,

Rich (BB code):
Option Explicit
    
Sub CallIt()
    MsgBox PickALetter("S", "D", "T")
End Sub
    
Function PickALetter(ParamArray Letters()) As String
    
    If UBound(Letters) - LBound(Letters) Then
        PickALetter = Letters(Int((UBound(Letters) - LBound(Letters) + 1) * Rnd))
    Else
        PickALetter = Letters(0)
    End If
End Function
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,200
Members
449,072
Latest member
DW Draft

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