"Run-time error '1004' " when using FormulaR1C1? - excel

I am creating a template for a process route card for our factory, which configures itself based on a few inputs. One section of this is a build log for serialised parts.
I want to insert this formula:
=IFERROR(IF(RIGHT(K122,4)+1< $E$17+1, IF(AND(MID(K122,23,1)="0",NOT(RIGHT(K122,1)="9")),CONCAT(LEFT(K122,(LEN(K122)-4)),IF(LEN(RIGHT(K122,4)+1)=1,CONCAT("000",RIGHT(K122,4)+1),IF(LEN(RIGHT(K122,4)+1)=2,CONCAT("00",RIGHT(K122,4)+1),IF(LEN(RIGHT(K122,4)+1)=3,CONCAT("0",RIGHT(K122,4)+1),RIGHT(K122,4)+1)))),IF(AND(MID(K122,22,1)="0",NOT(MID(K122,23,2)="99")),CONCAT(LEFT(K122,(LEN(K122)-4)),IF(LEN(RIGHT(K122,4)+1)=1,CONCAT("000",RIGHT(K122,4)+1),IF(LEN(RIGHT(K122,4)+1)=2,CONCAT("00",RIGHT(K122,4)+1),IF(LEN(RIGHT(K122,4)+1)=3,CONCAT("0",RIGHT(K122,4)+1),RIGHT(K122,4)+1)))),IF(AND(MID(K122,21,1)="0",NOT(MID(K122,22,3)="999")),CONCAT(LEFT(K122,(LEN(K122)-4)),IF(LEN(RIGHT(K122,4)+1)=1,CONCAT("000",RIGHT(K122,4)+1),IF(LEN(RIGHT(K122,4)+1)=2,CONCAT("00",RIGHT(K122,4)+1),IF(LEN(RIGHT(K122,4)+1)=3,CONCAT("0",RIGHT(K122,4)+1),RIGHT(K122,4)+1)))),CONCAT(LEFT(K122,(LEN(K122)-4)),IF(LEN(RIGHT(K122,4)+1)=1,CONCAT("000",RIGHT(K122,4)+1),IF(LEN(RIGHT(K122,4)+1)=2,CONCAT("00",RIGHT(K122,4)+1),IF(LEN(RIGHT(K122,4)+1)=3,CONCAT("0",RIGHT(K122,4)+1),RIGHT(K122,4)+1))))))),""),"")
in many cells, using R1C1 notation, due to the varying absolute position in the spreadsheet of the structure this formula is a part of. This formula works.
Converting this formula to R1C1 notation I get:
=IFERROR(IF(RIGHT(R[-2]C[0],4)+1< $E$17+1, IF(AND(MID(R[-2]C[0],23,1)=""0"",NOT(RIGHT(R[-2]C[0],1)=""9"")),CONCAT(LEFT(R[-2]C[0],(LEN(R[-2]C[0])-4)),IF(LEN(RIGHT(R[-2]C[0],4)+1)=1,CONCAT(""000"",RIGHT(R[-2]C[0],4)+1),IF(LEN(RIGHT(R[-2]C[0],4)+1)=2,CONCAT(""00"",RIGHT(R[-2]C[0],4)+1),IF(LEN(RIGHT(R[-2]C[0],4)+1)=3,CONCAT(""0"",RIGHT(R[-2]C[0],4)+1),RIGHT(R[-2]C[0],4)+1)))),IF(AND(MID(R[-2]C[0],22,1)=""0"",NOT(MID(R[-2]C[0],23,2)=""99"")),CONCAT(LEFT(R[-2]C[0],(LEN(R[-2]C[0])-4)),IF(LEN(RIGHT(R[-2]C[0],4)+1)=1,CONCAT(""000"",RIGHT(R[-2]C[0],4)+1),IF(LEN(RIGHT(R[-2]C[0],4)+1)=2,CONCAT(""00"",RIGHT(R[-2]C[0],4)+1),IF(LEN(RIGHT(R[-2]C[0],4)+1)=3,CONCAT(""0"",RIGHT(R[-2]C[0],4)+1),RIGHT(R[-2]C[0],4)+1)))),IF(AND(MID(R[-2]C[0],21,1)=""0"",NOT(MID(R[-2]C[0],22,3)=""999"")),CONCAT(LEFT(R[-2]C[0],(LEN(R[-2]C[0])-4)),IF(LEN(RIGHT(R[-2]C[0],4)+1)=1,CONCAT(""000"",RIGHT(R[-2]C[0],4)+1),IF(LEN(RIGHT(R[-2]C[0],4)+1)=2,CONCAT(""00"",RIGHT(R[-2]C[0],4)+1),IF(LEN(RIGHT(R[-2]C[0],4)+1)=3,CONCAT(""0"",RIGHT(R[-2]C[0],4)+1),RIGHT(R[-2]C[0],4)+1)))),CONCAT(LEFT(R[-2]C[0],(LEN(R[-2]C[0])-4)),IF(LEN(RIGHT(R[-2]C[0],4)+1)=1,CONCAT(""000"",RIGHT(R[-2]C[0],4)+1),IF(LEN(RIGHT(R[-2]C[0],4)+1)=2,CONCAT(""00"",RIGHT(R[-2]C[0],4)+1),IF(LEN(RIGHT(R[-2]C[0],4)+1)=3,CONCAT(""0"",RIGHT(R[-2]C[0],4)+1),RIGHT(R[-2]C[0],4)+1))))))),""""),"""")
Inserting into my VBA gave me an error, as my line of code was too long, so I split the text string in two, declared them as constants, and implemented it as so:
Private Const Formula1 As String = "=IFERROR(IF(RIGHT(R[-2]C[0],4)+1< $E$17+1, IF(AND(MID(R[-2]C[0],23,1)=""0"",NOT(RIGHT(R[-2]C[0],1)=""9"")),CONCAT(LEFT(R[-2]C[0],(LEN(R[-2]C[0])-4)),IF(LEN(RIGHT(R[-2]C[0],4)+1)=1,CONCAT(""000"",RIGHT(R[-2]C[0],4)+1),IF(LEN(RIGHT(R[-2]C[0],4)+1)=2,CONCAT(""00"",RIGHT(R[-2]C[0],4)+1),IF(LEN(RIGHT(R[-2]C[0],4)+1)=3,CONCAT(""0"",RIGHT(R[-2]C[0],4)+1),RIGHT(R[-2]C[0],4)+1)))),IF(AND(MID(R[-2]C[0],22,1)=""0"",NOT(MID(R[-2]C[0],23,2)=""99"")),CONCAT(LEFT(R[-2]C[0],(LEN(R[-2]C[0])-4)),IF(LEN(RIGHT(R[-2]C[0],4)+1)=1,CONCAT(""000"",RIGHT(R[-2]C[0],4)+1),IF(LEN(RIGHT(R[-2]C[0],4)+1)=2,CONCAT(""00"",RIGHT(R[-2]C[0],4)+1),IF(LEN(RIGHT(R[-2]C[0],4)+1)=3,CONCAT(""0"",RIGHT(R[-2]C[0],4)+1),RIGHT(R[-2]C[0],4)+1)))),IF(AND(MID(R[-2]C[0],21,1)=""0"",NOT(MID(R[-2]C[0],22,3)=""999"")),CONCAT(LEFT(R[-2]C[0],(LEN(R[-2]C[0])-4)),IF(LEN(RIGHT(R[-2]C[0],4)+1)=1,CONCAT(""000"",RIGHT(R[-2]C[0],4)+1),IF(LEN(RIGHT(R[-2]C[0],4)+1)=2,CONCAT(""00"",RIGHT(R[-2]C[0],4)+1),"
Private Const Formula2 As String = "IF(LEN(RIGHT(R[-2]C[0],4)+1)=3,CONCAT(""0"",RIGHT(R[-2]C[0],4)+1),RIGHT(R[-2]C[0],4)+1)))),CONCAT(LEFT(R[-2]C[0],(LEN(R[-2]C[0])-4)),IF(LEN(RIGHT(R[-2]C[0],4)+1)=1,CONCAT(""000"",RIGHT(R[-2]C[0],4)+1),IF(LEN(RIGHT(R[-2]C[0],4)+1)=2,CONCAT(""00"",RIGHT(R[-2]C[0],4)+1),IF(LEN(RIGHT(R[-2]C[0],4)+1)=3,CONCAT(""0"",RIGHT(R[-2]C[0],4)+1),RIGHT(R[-2]C[0],4)+1))))))),""""),"""")"
Sub BuildBuildLog()
RemoveBuildLog
With Sheets(WSPRC)
count = 1
For i = 1 To PRCLength ' incrementing rows in the documents
If InStr(1, LCase(.Cells(i, 1).Value), "blhead01", vbBinaryCompare) Then
.Cells(i, 1).EntireRow.Hidden = False
ElseIf InStr(1, LCase(.Cells(i, 1).Value), "blhead02", vbBinaryCompare) Then
.Cells(i, 1).EntireRow.Hidden = False
ElseIf InStr(1, LCase(.Cells(i, 1).Value), "blhead03", vbBinaryCompare) Then
.Cells(i, 1).EntireRow.Hidden = False
For j = 1 To noHeaders + 1 'counting through the pages of the build log - (+1 to allow for a page for rework log)
If j > noHeaders Then 'last page of build log is blank - to allow records of reworked assemblies.
.Cells(((noHeaders - 1) * 12) + 15, 1).Value = "Rework Log"
For k = 1 To 20 'Counting the rows in the build log - 20 per page
.Cells(i + k, 1).EntireRow.Hidden = False
Call formatBLRow((2 * k) + (i - 1), j)
Next k
Else
For k = 1 To 20 'Counting the rows in the build log - 20 per page
If count < batchqty + 1 Then
'add a line to the build log
If count = 1 Then
.Cells((2 * k) + (i - 1), 12 * j).Formula = "=CONCAT($I$8,"": "",RIGHT($C$7,4),""-"",B31,""-"",E31)"
ElseIf k = 1 Then
.Cells((2 * k) + (i - 1), 12 * j).FormulaR1C1 = Formula3 & Formula4
Else
.Cells((2 * k) + (i - 1), 12 * j).FormulaR1C1 = Formula1 & Formula2
End If
Call formatBLRow((2 * k) + (i - 1), j)
Else
Exit For 'Exit for loop if count of rows in build log is greater or equal to batch quantity
End If
count = count + 1
Next k
End If
Next j
End If
Next i
End With
End Sub
The error:
Run-time error '1004' Application-defined or object-defined error`
occurs the first time formulaR1C1 is called, during the
For k = 1 To 20 'Counting the rows in the build log - 20 per page count`
for loop, for count = 2, k=2.
Although the formula is long, it is shorter than the limit of the length of the property I am trying to insert it into.

I just realised my error.. I didn't fully convert the formula into R1C1 notation, I had left the lone explicit Cell reference in A1 notation
$E$17
..Converting that to R17C5 fixed it.
Sorry for the long read for the elementary issue.
Regards,

Related

Find Distance between different coordinates

I have Location data (latitude and longitude) of 1000's of locations and need to compute the distance between each of them taken two combinations at a time.
Example:
Let's just say I have four location data (latitude and longitude data) and want to compute the distance between them
Location Latitude Longitude
1. New York(L1) 40.7128° N 74.0060° W
2. Paris(L2) 48.8566° N 2.3522° E
3. London(L3) 51.5074° N 0.1278° W
4. Moscow(L4) 55.7558° N 37.6173° E
Need to calculate the distance between possible combinations i.e distance between L1&L2, L1&L3, L1&L4, L2&L3, L2&L4 and L3&L4
Excel Formula I'm using to compute distance is
=ACOS(COS(RADIANS(90-Lat1)) *COS(RADIANS(90-Lat2)) +SIN(RADIANS(90-Lat1)) *SIN(RADIANS(90-Lat2)) *COS(RADIANS(Long1-Long2))) *6371
How can I calculate it for large data set say 100's or 1000's of locations?
Alternatively, you can create a VBA function and then loop through your table.
Add this code to a Module in the VBA editor:
Public Function DistBetweenCoord(Lat1 As Double, Long1 As Double, Lat2 As Double, Long2 As Double)
'Cell Formula
'ACOS(COS(RADIANS(90-Lat1)) *COS(RADIANS(90-Lat2)) +SIN(RADIANS(90-Lat1)) *SIN(RADIANS(90-Lat2)) *COS(RADIANS(Long1-Long2))) *6371
With WorksheetFunction
A = Cos(.Radians(90 - Lat1))
B = Cos(.Radians(90 - Lat2))
C = Sin(.Radians(90 - Lat1))
D = Sin(.Radians(90 - Lat2))
E = Cos(.Radians(Long1 - Long2))
DistBetweenCoord = .Acos(A * B + C * D * E) * 6371
End With
End Function
Now you can access this through code or in cell. Here is an example of in-cell:
=DistBetweenCoord(C1,D1,C2,D2)
Here is how to loop through all possible combinations in another Sub. Output is in immediate window.
Sub CalcAllDistances()
With Worksheets("Sheet1")
For i = 1 To 4
For j = i To 4
If i <> j Then
Debug.Print .Cells(i, 2) & " to " & .Cells(j, 2) & ": " & DistBetweenCoord(.Cells(i, 3), .Cells(i, 4), .Cells(j, 3), .Cells(j, 4))
End If
Next j
Next i
End With
End Sub
EDIT - To change output to Sheet2 try the following:
Sub CalcAllDistances()
Dim wks_Output As Worksheet
Set wks_Output = Worksheets("Sheet2")
Dim OutputRow As Long: OutputRow = 1
With Worksheets("Sheet1")
For i = 1 To 4
For j = i To 4
If i <> j Then
wks_Output.Cells(OutputRow, 1).Value = .Cells(i, 2) & " to " & .Cells(j, 2)
wks_Output.Cells(OutputRow, 2).Value = DistBetweenCoord(.Cells(i, 3), .Cells(i, 4), .Cells(j, 3), .Cells(j, 4))
OutputRow = OutputRow + 1
End If
Next j
Next i
End With
End Sub
I would use a matrix.
Create a sheet (like 'GeocodeList' or something) for the geocodes, like your city|lat|lon in the question. Then create a sheet (like 'Distances') for a matrix, where the column and row labels are the city names. Then you can parameter your excel formula using V.LOOKUPs that look up exact codes from GeocodeList.
The formula would look like this (X is row number, Y is column letter.):
=ACOS(COS(RADIANS(90-VLOOKUP($A(X); GEOCODETABLE, LATCOLINDEX, 0)))
*COS(RADIANS(90-VLOOKUP((Y)$1; GEOCODETABLE; LATCOLINDEX, 0)))
+SIN(RADIANS(90-VLOOKUP($A(X); GEOCODETABLE, LATCOLINDEX, 0)))
*SIN(RADIANS(90-VLOOKUP((Y)$1; GEOCODETABLE; LATCOLINDEX, 0)))
*COS(RADIANS(VLOOKUP($A(X); GEOCODETABLE, LATCOLINDEX, 0)-VLOOKUP((Y)$1; GEOCODETABLE; LONCOLINDEX, 0))))
*6371
So basically the VLOOKUP automatically fetches your parameters, and you can extend the formula for the whole matrix.

Type Mismatch error adding 10 Seconds to the previous cell's value

I would like to write to a cell the previous cells time value + 10 seconds.
I have tried several approaches after a lot of googling, however below is what I started with and what I would like to understand is why this doesn't work - as in my head it is logical.
The cell data is in the special format DD:MM:YYYY HH:MM:SS - which is a reason this may not work, however if I add + (10 / (3600 * 24)) to the cell manually then it successfully adds on 10 seconds.
Dates are stored as custom and show up as 24/09/2018 08:41:09.
Public Sub Add_Row()
Dim Row As Variant
Dim LR As Long
Dim x As Integer
Dim y As Integer
LR = ActiveSheet.Range("B" & Rows.Count).End(xlUp).Row 'Counts number of rows
x = 1
Row = 1
Do Until x = LR
If Cells(Row, 2).Value <= 1 Then 'If the value of the cell is less than or equal to one do nothing and increment
Row = Row + 1
x = x + 1
Else
y = Cells(Row, 2).Value - 1 'Need a variable for the number of rows we require based on how many missed points we have
For k = 1 To y
ActiveSheet.Rows(Row).Insert Shift:=xlDown
Cells(Row, 1).Value = Cells(Row - 1, 1).Value + (10 / (3600 * 24))
Next
Row = Row + y + 1
x = x + 1
End If
Loop
End Sub
MUltiplying 3600 by 24 in VBA will give an overflow error, because the max value of a 16 bit integer (the default type for the result when both the input numbers are integers) is 32767. You can either use a "#" which will tell VBA that you want to treat the result as a double, like so:
Cells(Row, 1).Value = Cells(Row - 1, 1).Value + (10 / (3600# * 24))
OR you can use "#12:00:10 AM#" which represents 10 seconds, rather than attempting to calculate it, like so:
Cells(Row, 1).Value = Cells(Row - 1, 1).Value + #12:00:10 AM#
Hope this helps.

Excel VBA run-time error 1004: Application-defined or object-defined error

very novice user, having some difficulty getting this code up and running. I am attempting to calculate a value based on some other cells and iterating to minimize error. When running, I get the aforementioned error on the Cells(i, 17) = Cells(i, 5) line. Thoughts? Thank you.
Private Sub CommandButton1_Click()
Dim i As Long
A = 6.112
B = 17.67
C = 243.5
epsilon = 0.622
G = B * C
maxerror = 0.001
For i = 2 To Rows.Count
Next i
iter = 0
Cells(i, 17) = Cells(i, 5)
Do While iter < 50
iter = iter + 1
bt = B * Cells(i, 17)
tpc = Cells(i, 17) + C
d = (Cells(i, 9) / A) * Exp(-bt / tpc)
dm1 = d - 1#
f = (Cells(i, 5) - Cells(i, 17)) - Cells(i, 16) * (epsilon / dm1 - Cells(i, 13))
df = -G / (tpc * tpc)
df = d * df * Cells(i, 16) * epsilon / (dm1 * dm1) - 1#
cor = f / df
Cells(i, 17) = Cells(i, 5) - cor
If Abs(cor) < maxerror Then
Exit Do
End If
Loop
End Sub
When you exit that loop, the value of i is actually the amount of rows in the sheet +1 which is causing the error - you're trying to reference a row that doesn't exist.
If you want the last row in the sheet just use:
Dim i As Long
i = Rows.Count
Explanation:
For i = 1 To 10
Debug.Print i '// Prints 1,2,3,4,5,6,7,8,9,10 as expected
Next i '// When i = 10 and gets to this line, it still
'// increases the value before it exits the loop
Debug.Print i '// Prints 11
The problem here is that the for loop will have increased i beyond Rows.Count. That means that Cells(i, 17) = Cells(i, 5) is actually referring to the row immediately after the end of the spreadsheet.
Normally, we would not use i afterNext i. Normally, we only use the variable between the For and the Next. It's unclear to me what you expect theFor...Nextloop to achieve, because they usually are used to execute some code many times over, just changing a variable each time.
One thing you might find useful: You can step through the code line by line, using F8. Then you can inspect variables and other things to make sure they are as you're expecting.

Generate 5000 records in 2 columns of random number that being unique

How I can generate 5000 records in 2 columns of random numbers between 1 and 100 that being unique.
For example:
A B
----------------
1 98
1 23
37 98
6 56
93 18
. .
. .
. .
thanks
Excel formulas do not perform loops until a condition has been met. Any 'loop' or array processing must have a defined number of cycles. Further, RAND and RANDBETWEEN are volatile formulas that will recalculate anytime the workbook goes through a calculation cycle.
In VBA this would look like the following.
Sub Random_2500_x_2()
Dim rw As Long
For rw = 1 To 2500
Cells(rw, 1) = Int((100 - 1 + 1) * Rnd + 1)
Cells(rw, 2) = Int((100 - 1 + 1) * Rnd + 1)
Do Until Cells(rw, 2).Value <> Cells(rw, 1).Value
Cells(rw, 2) = Int((100 - 1 + 1) * Rnd + 1)
Loop
Next rw
End Sub
Here is a simple-minded approach using formulae. Whether it would be appropriate would depend on context.
First in the Formulas tab set calculation options to 'Manual'.
Put the following formula in a2:-
=RANDBETWEEN(1,100)
B is going to be a helper column. Put the following in B2:-
=RANDBETWEEN(1,99)
Column C is the second result that you want. Put the following in C2:-
=IF(B2<A2,B2,B2+1)
Pull the formulae down as required.
Each time you press 'Calculate Now', you will get a fresh set of random numbers.
However if you really need unique rows (every row to be different) you'd need a different approach - could generate a set of 4-digit numbers, split them into first and last pairs of digits and filter out ones where first and second were equal.
Generate the 4-digit number in A2:-
=RANDBETWEEN(1,9998)
Take the first two-digit number plus one in B2:-
=INT(A2/100)+1
Take the second 2-digit number plus one in C2:-
=MOD(A2,100)+1
Check for invalid numbers in D2:-
=OR(ISNUMBER(MATCH(A2,A$1:A1,0)),B2=C2)
Set up a running total of valid numbers in E2:-
=COUNTIF(D2:D$2,FALSE)
Here's how the second approach would look with checking for duplicate rows as well as duplicate numbers within a row. Note that you'd have to generate about 3,000 rows to get 2,500 distinct rows:-
First run this tiny macro:
Sub dural()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
k = 1
For i = 1 To 100
For j = 1 To 100
Cells(k, 1) = i
Cells(k, 2) = j
Cells(k, 3).Formula = "=rand()"
k = k + 1
Next j
Next i
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = True
End Sub
Then sort cols A,B,C by column C.Then pick the first 5000 rows.
EDIT#1:
To remove cases in which the value in column A is the same as the value in column B use this macro instead:
Sub dural()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
k = 1
For i = 1 To 100
For j = 1 To 100
If i <> j Then
Cells(k, 1) = i
Cells(k, 2) = j
Cells(k, 3).Formula = "=rand()"
k = k + 1
End If
Next j
Next i
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = True
End Sub

Filling Array once worked, does not anymore (subscript out of range)

The code I have once worked to add/delete groups of rows (requirements). I needed to modify the code so that if the 1st row of the group met certain criteria (i.e, the requirement was not one we wanted to consider), (1) we would not count it and (2), we would hide the group (current and subsequent 2 rows). This all works fine.
The problem is that now that I incorporated these changes, I get an error in another section of the code and for the life of me I cannot figure out why. I have stepped through this and am extremely frustrated. I am reaching out for help, and am hoping someone can see my error(!)
We calculate the start and finish row numbers within a grouping, and store these calculations in Arrays called "Start" and "Finish." I use the ReDim statement to initialize my arrays, because I thought that could be part of the problem, but no.
Any insight as to why my "subscripts are out of range" would be appreciated. I have traced through the logic, investigated this error, and read about the syntax/usage of VBA arrays. I don't know what else to do. Thanks in advance. Here are the relevant lines:
Sub Button1_Click()
Cells.Select
Selection.ClearOutline
If Cells.EntireRow.Hidden Then Cells.EntireRow.Hidden = False
Dim Start() As Integer
Dim Finish() As Integer
Dim p As Integer, q As Integer
ReDim Start(0, 50)
ReDim Finish(0, 50)
The following is embedded in logic that loops through all the rows in the spreadsheet:
i = 1
For Row = 4 To Cells(1, 6).Value - 1
If Begin Then
If Cells(Row, 3).Interior.ColorIndex = 44 Then
Start(i) = Row + 1
j = Cells(Row, 2).Value
Begin = False
End If
Else
If Cells(Row, 2).Value = j + 1 Or Cells(Row, 2).Interior.ColorIndex = 37 Then
Finish(i) = Row - 1
Begin = True
i = i + 1
Row = Row - 1
End If
End If
Next
The block I changed is as follows (code I added is last block where I attempt to hide rows). It precedes the previous. I am wondering how my change could have affect the above(?!)
If Cells(Row, 5).Value = "Requirement" Then
Range(Cells(Row, 4), Cells(Row, 4)).Interior.ColorIndex = 40
Rows(Row).Font.Bold = True
Rows(Row).Font.Italic = False
Rows(Row).Font.ColorIndex = 1 'Black
If Cells(Row - 3, 4).Value = "" Then 'this is requirement #1
Cells(Row, 4).Value = 1
Else
Cells(Row, 4).Value = Cells(Row - 3, 4).Value + 1
End If
p = Row
q = p + 2
Rows(p & ":" & q).Select
If Cells(p, 19).Value = "4" Then
Selection.EntireRow.Hidden = True
Else
Selection.EntireRow.Hidden = False
End If
Redim Start(0,50) makes the array dimensions 0 to 0, 0 to 50 i.e. a 2d array.
This means that when you call the array you need to provide parameters for both dimensions I.E: Start(0,i) or Finish(0,i). Calling Start(i) will result in the error you mentioned.
The easiest way to get rid of the error is to change your Redim lines to
ReDim Start(50)
ReDim Finish(50)
which is what I assume you meant to do in the first place.
Note: Based upon the format you used, you may have been meaning to do Start(0 to 50) and Finish(0 to 50) initially. The comma in the dimensioning indicates another dimension instead of a separation between lower and upper bounds.

Resources