Array subscript out of range issue

get2noesks

New Member
Joined
Jul 15, 2015
Messages
24
Hi Team,

I am getting an error while executing the code detailed below.

Private Sub Workbook_Open()
Dim WS1 As Worksheet
Dim WS2 As Worksheet

Set WS1 = Worksheets("Sheet1")
Set WS2 = Worksheets("Sheet2")

Dim testCollection As Collection
Dim SIZE As Integer, sortCol As Integer, sortRow As Integer, loopcntl As Integer
Set testCollection = getValuesToSort
'Debug.Print testCollection.Item(3)

'Debug.Print testCollection.Count
sortRow = 1
loopcntl = 1
SIZE = testCollection.Count
If SIZE <= 0 Then
MsgBox ("Nothing To Search for a sort")
End If

For loopcntl = 1 To SIZE
'MsgBox (loopCntl)
'MsgBox testCollection.Item(loopCntl)
'Call sortData(sortRow, loopCntl)
Dim completeArray() As String, arrayLeft() As String, arrayRight() As String
Dim arrayInputCntlVar As Integer, firstIndex As Integer
firstIndex = sortRow
arrayInputCntlVar = testCollection.Item(loopcntl)

Dim i As Integer
i = 0

While (WS1.Cells(sortRow + 1, arrayInputCntlVar)) <> ""
completeArray(i) = WS1.Cells(sortRow + 1, arrayInputCntlVar).ValuesortRow = sortRow + 1
i = i + 1
Wend

Dim lastIndex As Integer
lastIndex = i + 1
Call MergeSort(completeArray(), firstIndex, lastIndex)

Next loopcntl

End Sub

Regards
Saurabh
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Hi

I haven't checked the rest of your code in detail, but

completeArray(i) = WS1.Cells(sortRow + 1, arrayInputCntlVar).ValuesortRow = sortRow + 1

should be on 2 rows

completeArray(i) = WS1.Cells(sortRow + 1, arrayInputCntlVar).Value
sortRow = sortRow + 1
 
Upvote 0
Hi Roger,

I have it in the same way as you have mentioned. The post shows it this way because of a typo.

Regards
Saurabh
 
Upvote 0
Hi Andrew,

Request you to please elaborate on that because I did dimension the array with the line of code 'Dim completeArray() As String'

Regards
Saurabh
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top