I'm working with MS-Excel VBA Programming for the absolute beginner and I'm having difficulty creating the code for this particular challenge.
I'm tasked with creating 25 random numbers from 0-99 and then placing the values returned into an array which will be displayed alongside the numbers generated. However, I've clearly done it incorrectly and am receiving a Run-Time error '9': stating "Subscript out of range"
I'm using Excel 6.5 and windows XP.
Here is my code. (Forgive my random dim statements which are apparently not used properly, or at all).
Dim intTwoDimArray(4, 4) As Integer
Dim objMyRange As Object
Dim objMyCell As Object
Dim strArray(1, 9) As String
Dim intArrayRange As Object
Dim intColumnIndex As Integer
Dim intRowIndex As Integer
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set objMyRange = Range("A1:E5")
For Each objMyCell In objMyRange
objMyCell = Int(Rnd * 100) + 1
Next objMyCell
Set intArrayRange = Range("F1:F25")
For intRowIndex = 0 To 1
For intColumnIndex = 0 To 9
strArray(intRowIndex, intColumnIndex) = Cells(intRowIndex + 1, Chr(65 + intColumnIndex))
Next intColumnIndex
Next intRowIndex
Cells((intColumnIndex + (intRowIndex * 4)) + 1, "F").Value = intTwoDimArray(intRowIndex, intColumnIndex)
End Sub
Highlighted in Red at the bottom is where the code seems to be hanging up, or is flagged under the debug.
Any help would be greatly appreciated!!
Thanks in advance,
b-dub
I'm tasked with creating 25 random numbers from 0-99 and then placing the values returned into an array which will be displayed alongside the numbers generated. However, I've clearly done it incorrectly and am receiving a Run-Time error '9': stating "Subscript out of range"
I'm using Excel 6.5 and windows XP.
Here is my code. (Forgive my random dim statements which are apparently not used properly, or at all).
Dim intTwoDimArray(4, 4) As Integer
Dim objMyRange As Object
Dim objMyCell As Object
Dim strArray(1, 9) As String
Dim intArrayRange As Object
Dim intColumnIndex As Integer
Dim intRowIndex As Integer
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Set objMyRange = Range("A1:E5")
For Each objMyCell In objMyRange
objMyCell = Int(Rnd * 100) + 1
Next objMyCell
Set intArrayRange = Range("F1:F25")
For intRowIndex = 0 To 1
For intColumnIndex = 0 To 9
strArray(intRowIndex, intColumnIndex) = Cells(intRowIndex + 1, Chr(65 + intColumnIndex))
Next intColumnIndex
Next intRowIndex
Cells((intColumnIndex + (intRowIndex * 4)) + 1, "F").Value = intTwoDimArray(intRowIndex, intColumnIndex)
End Sub
Highlighted in Red at the bottom is where the code seems to be hanging up, or is flagged under the debug.
Any help would be greatly appreciated!!
Thanks in advance,
b-dub