I defined the following Array:
Global Locations_Array() As String
ThisWorkbook.Worksheets("Locations").Activate
TotalRowsLocations = ActiveSheet.UsedRange.Rows.Count
ReDim Locations_Array(1 To TotalRowsLocations, 1 To 6) As String
According to this I expect the first row of the array to be row 1. I used this array to name new worksheets in my workbook, and that started at 1, and ended where it should.
However now I call again on this array with the following code:
Sub Get_Lat_Lng()
Dim row As Integer
Dim data_row As Integer
Call Fill_Array_Locations
totalrowsdata = ThisWorkbook.Worksheets("Locations").UsedRange.Rows.Count - 1
TotalRowsDataLookup = ThisWorkbook.Worksheets(Locations_Array(row, 1)).UsedRange.Rows.Count
For row = 2 To totalrowsdata
ThisWorkbook.Worksheets(Locations_Array(row, 1)).Activate
If (UCase(Locations_Array(row, 5))) = (UCase(ThisWorkbook.ActiveSheet(row, 7))) And (UCase(Locations_Array(row, 6))) = (UCase(Worksheet.ActiveSheet(row, 8))) Then
For data_row = 1 To TotalRowsDataLookup
If (UCase(Locations_Array(row, 2)) = UCase(ThisWorkbook.Worksheets(Locations_Array(data_row, 1)).Cells(data_row, 5))) Then
Cells(data_row, 7) = Locations_Array(row, 5)
Cells(data_row, 8) = Locations_Array(row, 6)
Exit For
End If
Next data_row
Exit For
End If
Next row
End Sub
And it returns an "Run-time error '9': Subscript out of range" When I check for the values in this line of code row has the value of 0 due to being an Integer. Is there a way to make this Integer start at 1 instead of 0? I found the option to set :
Option Base 1
But this interferes with the rest of my code.
row?0element of array but you userowas index when its value is equal to 0.Locations_Array(row, 1). You shouls assignrow1 or whatever is needed befor you use it as index.Row = 1.Option Base 1has no effect on the initialisation of the numeric variables. They are equal to 0 by default in vba.option basedetermines first index of arrays whether they are equal to 0 or 1. Also, you have determined first indexes of your array is equal to 1.