Originally Posted by
Andy Pope
msgbox application.WorksheetFunction.Choose(application.WorksheetFunction.RandBetween(1,11),"P1","P2","P3","P4","P5","P6","P7","P8","P9","P10","P11")
VB has its own Choose function which works the same as the Excel worksheet CHOOSE function (for the most part), so you can remove what I highlighted in red and this code line will work the same
I would note, however, since no variables are involved, you could just do this...
MsgBox [Choose(RandBetween(1,11),"P1","P2","P3","P4","P5","P6","P7","P8","P9","P10","P11")]
Or, use the INDEX function (which I think might be a more efficient function) instead of the CHOOSE function like this...
MsgBox [INDEX({"P1","P2","P3","P4","P5","P6","P7","P8","P9","P10","P11"},RandBetween(1,11))]
Bookmarks