Pick letter randomly

Temporary-Failure

Board Regular
Joined
Jul 16, 2010
Messages
137
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:

Some videos you may like

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

doublej_jj

Board Regular
Joined
Apr 9, 2010
Messages
147
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
 

GTO

MrExcel MVP
Joined
Dec 9, 2008
Messages
6,154
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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,307
Messages
5,600,869
Members
414,411
Latest member
Snowmanaus

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
Top