Combining numbers and strings to generate random output
I have the following code that produces a random number from 1 to 36. I would actually like to produce a random string from the names btn1 to btn36. Is there a way to do this?
Dim Low As Double
Dim Hig开发者_StackOverflow社区h As Double
Low = 1
High = 36
R = Int((High - Low + 1) * Rnd() + Low)
Sheets("ITEMS DATA").Range("K21").Value = R
Yes. A simple string concatenation will work. Just append your random number to a "btn"
string prefix like this:
Sheets("ITEMS DATA").Range("K21").Value = "btn" & R
精彩评论