View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Alan Beban Alan Beban is offline
external usenet poster
 
Posts: 200
Default Passing indexed array value to VBA function

You haven't provided enough data for me to work with the snippet. E.g.,
what is q? What is totalRange? With what are lastNumber and firstNumber
initialized?

Alan Beban

wrote:
HERE IS A CODE SNIPPIT

Sub randomgen()
Dim randomWeights() As Integer
Dim extraWeights() As Integer
Dim temp() As Integer
Dim lastNumber() As Integer
Dim firstNumber() As Integer
Dim extras(), randoms()

ReDim unsortedRandoms(Cells(2, 2) * 5)
ReDim unsortedExtras(Cells(3, 2) * 5)
ReDim firstNumber(Cells(4, 2))
ReDim lastNumber(Cells(4, 2))
ReDim randomWeights(Cells(4, 2))
ReDim extraWeights(Cells(4, 2))

randomWeights(q) = Round((lastNumber(q) - firstNumber(q)) *
Cells(2, 2) * 5 / totalRange)
extraWeights(q) = Round((lastNumber(q) - firstNumber(q)) * Cells(3,
2) * 5 / totalRange)

temp = RandomNumbers(lastNumber(q), firstNumber(q),
(randomWeights(q) + extraWeights(q)))

end sub

Public Function RandomNumbers(Upper As Integer, _
Optional Lower As Integer = 1, _
Optional HowMany As Integer = 1, _
Optional Unique As Boolean = True) As Variant

end function

END OF CODE SNIPPIT

I want to call the RandomNumber function using the values in those
arrays at index q. What am I doing wrong? I get a runtime error 13 type
mismatch on the RandomNumbers function call.

Thanks in advance,
Phil