For some reason, nothing happens when I run this macro. What might I be doing wrong?
(I’m trying to fill each cell in the range with a randomly selected string.)
Sub ktr()
Dim dataRange As Range
Set dataRange = Range("A1:V35")
For Each cell In dataRange
response = azerothSays()
cell.Value = response
Next cell
End Sub
Private Function azerothSays()
Dim result As String
Select Case Rnd(6)
Case 1
result = "CELIBACY"
Case 2
result = "WORMS"
Case 3
result = "AGING"
Case 4
result = "MARRIAGE"
Case 5
result = "CHEMISTRY"
Case 6
result = "DISINTIGRATE"
End Select
azerothSays = result
End Function
Rnd() always produces a (decimal) number between 0 and 1. So, if you wanted to get a random number from 1 to 6, try replacing your Select Case line with this:
The “math part” finds a number between 1 and 6, and Int() converts it to a whole number.
In general, the formula is