ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Please help - What am i doing wrong with this array? (https://www.excelbanter.com/excel-programming/299114-please-help-what-am-i-doing-wrong-array.html)

acunnold

Please help - What am i doing wrong with this array?
 
I am trying to input random values from a range in excel into an array
What am I doing wrong?

From a damsel in distress!

----
Option Explicit
Option Base 1


Sub testing3()
Dim Vt() As Double
Dim j As Long
Dim i As Long

ReDim Preserve Vt(1 To 40)
For i = 1 To 40
j = Int(Rnd() * 1100)
Vt(i) = Worksheets("data").Cells(1, j)
Next i
End Su

--
Message posted from http://www.ExcelForum.com


Alan Beban[_2_]

Please help - What am i doing wrong with this array?
 
j cannot be greater than 256, the maximum number of columns in Excel.

Alan Beban

acunnold < wrote:

I am trying to input random values from a range in excel into an array.
What am I doing wrong?

From a damsel in distress!

----
Option Explicit
Option Base 1


Sub testing3()
Dim Vt() As Double
Dim j As Long
Dim i As Long

ReDim Preserve Vt(1 To 40)
For i = 1 To 40
j = Int(Rnd() * 1100)
Vt(i) = Worksheets("data").Cells(1, j)
Next i
End Sub


---
Message posted from http://www.ExcelForum.com/


Frank Kabel

Please help - What am i doing wrong with this array?
 
Hi
see your other post. try replacing
j = Int(Rnd() * 1100)

with
j = Int(Rnd() * 10)+1

Note: j has to be between 1 and 256

--
Regards
Frank Kabel
Frankfurt, Germany

"acunnold " schrieb im
Newsbeitrag ...
I am trying to input random values from a range in excel into an

array.
What am I doing wrong?

From a damsel in distress!

----
Option Explicit
Option Base 1


Sub testing3()
Dim Vt() As Double
Dim j As Long
Dim i As Long

ReDim Preserve Vt(1 To 40)
For i = 1 To 40
j = Int(Rnd() * 1100)
Vt(i) = Worksheets("data").Cells(1, j)
Next i
End Sub


---
Message posted from http://www.ExcelForum.com/




All times are GMT +1. The time now is 08:53 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com