Return specified but random letters - an example

  • Thread starter aztecbrainsurgeon
  • Start date
A

aztecbrainsurgeon

no question here, just an example procedure for the archive

Sub RandomLetterGenerateSpecific()

'Return randomly distributed but user-specified letters for each cell
in selection
'Works by dividing the result of rand() by the number of letters
'to get the evaluate range for each letter.

Dim tempvalue As Double
Dim lvalue1, lvalue2, lvalue3, lvalue4, lvalue5 As String
Dim lvalue6, lvalue7, lvalue8, lvalue9, lvalue10 As String
'***********************************************************
'Assign specific values here:
lvalue1 = "A"
lvalue2 = "C"
lvalue3 = "L"
lvalue4 = "M"
lvalue5 = "O"
lvalue6 = "Q"
lvalue7 = "U"
lvalue8 = "W"
lvalue9 = "X"
lvalue10 = "Z"
'***********************************************************


On Error Resume Next
Selection.FormulaR1C1 = "=RAND()"

'Paste value the formulas

Selection.Value = Selection.Value

'Insert specific letters based on Rand() value resident in each
cell

For Each c In Selection
'set up temporary variable for c.value
tempvalue = c.Value

If 0 <= tempvalue And tempvalue <= 0.1 Then
c.Value = lvalue1
End If
If 0.1 < tempvalue And tempvalue <= 0.2 Then
c.Value = lvalue2
End If
If 0.2 < tempvalue And tempvalue <= 0.3 Then
c.Value = lvalue3
End If
If 0.3 < tempvalue And tempvalue <= 0.4 Then
c.Value = lvalue4
End If

If 0.4 < tempvalue And tempvalue <= 0.5 Then
c.Value = lvalue5
End If
If 0.5 < tempvalue And tempvalue <= 0.6 Then
c.Value = lvalue6
End If

If 0.6 < tempvalue And tempvalue <= 0.7 Then
c.Value = lvalue7
End If

If 0.7 < tempvalue And tempvalue <= 0.8 Then
c.Value = lvalue8
End If
If 0.8 < tempvalue And tempvalue <= 0.9 Then
c.Value = lvalue9
End If

If tempvalue > 0.9 Then
c.Value = lvalue10
End If

Next c
End Sub

search critera
Return specified but random letters
Input random but specific letters
return specified letters with random distribution
randomly distributed target letters
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top