The code below crashes at the "END SUB"of the"MAIN" sub. I have search this and other sites but I can't find a solution. The frustrating part is the code works perfectly until it crashes. And there is no error message. I don't think the code is very complex and the file I am working with is not very large (6k lines). I tried copying & pasting the code as well as the data into a fresh workbook. That did not help.
Option ExplicitDim wsData As WorksheetSub Main() On Error GoTo ProcError Dim arrTrading() As Variant Dim arrCenter() As Variant Dim arrCategory() As Variant Dim arrCountry() As Variant Dim lastRow As Long TurnOffFunctionality Set wsData = Sheets("State Package Data") lastRow = getLastRowByEndUp(wsData, 1) wsData.Range("M2:M" & lastRow).Clear wsData.Range("n2:n" & lastRow).Clear wsData.Range("o2:o" & lastRow).Clear createArrays arrTrading, arrCenter, arrCategory, arrCountry lookup arrCountry, lastRow, "j", 20, "n", 8, "country" lookup arrCategory, lastRow, "f", 1, "m", 3, "category" lookup arrTrading, lastRow, "j", 1, "o", 3, "trading partner" TurnOnFunctionalityProcError: MsgBox Err.DescriptionEnd Sub
Sub lookup(arr As Variant, lastRow As Long, lookupCol As String, matchCol As Long, _ postCol As String, returnCol As Long, name As String) Dim i As Long Dim x As Long Dim lookupValue As String Dim matchValue As String For i = 2 To lastRow lookupValue = wsData.Cells(i, lookupCol) For x = 2 To UBound(arr) matchValue = arr(x, matchCol) If lookupValue = matchValue Then wsData.Cells(i, postCol) = arr(x, returnCol) Exit For End If Next x Next i Debug.Print nameEnd Sub
Sub createArrays(arrTrading As Variant, arrCenter As Variant, arrCategory As Variant, arrCountry As Variant) Sheets("Mapping").Activate arrCategory = Range("g1").CurrentRegion arrCenter = Range("k1").CurrentRegion arrTrading = Range("n1").CurrentRegion Sheets("BPC Consol Ownership").Activate arrCountry = Range("a1").CurrentRegionEnd Sub