TessieBear99
New Member
- Joined
- Aug 26, 2018
- Messages
- 20
- Office Version
- 365
- Platform
- Windows
I need to be able to generate a random number between 1 and x, with x being the number of people listed in my worksheet. The formula I have to do this works, it is:
Now I need to create a macro to assign to my button so that when the button is clicked, that formula runs and the value is pasted into E1. I've tried this with the following code but when I run it, it comes out with "TRUE" in E1 instead of the value.
Can someone please assist?
Excel Formula:
=RAND()*(COUNTIF(B2:B198,"<>"&"")-1)+1
Now I need to create a macro to assign to my button so that when the button is clicked, that formula runs and the value is pasted into E1. I've tried this with the following code but when I run it, it comes out with "TRUE" in E1 instead of the value.
VBA Code:
Sub RandomNumberGenerator()
'Generates random number between 1 and total number of names listed
Range("E1").Formula = "=RAND()*(COUNTIF(B2:B198," <> " & "")-1)+1"
Range("E1").Copy
Range("E1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End Sub
Can someone please assist?