excel vba - VBA Random Element from Array , Subscript out of Range error -


I'm vba noob so be easy for me.

I want to select a random array element in my card_range_string array (random typing, see the last line) but I get a "out of bounds" error What could be wrong?

  sub gener_random () 'generates a random card as slow random_card long: random_card = Int (Math.Rnd * 13) + 1 dim random_type random_symbol variable as string dim Dim card_Range_string () as the variant: Card_range_string = Range ("A1: A4"). Variable as value dim card_range_simbol (): Card_Range_Simbol = Range ("B1: B4"). Value random_type = card_range_string (Int (Math.Rnd * 3)) End Sub  

I Solved it Remember that arrays are two-dimensional, so I missed only to exclude the second dimension. Creating: random_type = card_range_string (int (Math.Rnd * 4 + 1), 1) solves the problem


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -