Sub Test()
Dim rng As Range, arrDec, arrCon, arrTop, arrLeft, i As Long, j As Long, p1 As Long, p2 As Long, startTime As Single, endTime As Single
'Log start timer
startTime = Timer
'Get arrays
arrDec = Sheets("decimal").Range("A1").CurrentRegion.Value
With Sheets("Cty Contracts").Range("A1").CurrentRegion
Set rng = .Range("E2:" & Split(.Address, ":")(1))
arrCon = Sheets("Contract").Range(rng.Address).Value
arrTop = rng.Offset(-1).Resize(1).Value
arrLeft = rng.Offset(, -rng.Column + 1).Resize(, 1).Value
End With
'Change items to be matched to uppercase
For i = 1 To UBound(arrDec, 1): arrDec(i, 1) = UCase$(arrDec(i, 1)): Next i
For i = 1 To UBound(arrDec, 2): arrDec(1, i) = UCase$(arrDec(1, i)): Next i
For i = 1 To UBound(arrTop, 2): arrTop(1, i) = UCase$(arrTop(1, i)): Next i
For i = 1 To UBound(arrLeft, 1): arrLeft(i, 1) = UCase$(arrLeft(i, 1)): Next i
'Get index
For i = 1 To UBound(arrTop, 2)
For j = 1 To UBound(arrDec, 2)
If arrTop(1, i) = arrDec(1, j) Or Left$(arrTop(1, i), 12) = arrDec(1, j) Then arrTop(1, i) = j: Exit For
Next j
If Not IsNumeric(arrTop(1, i)) Then arrTop(1, i) = 0
Next i
For i = 1 To UBound(arrLeft, 1)
For j = 1 To UBound(arrDec, 1)
If arrLeft(i, 1) = arrDec(j, 1) Then arrLeft(i, 1) = j: Exit For
Next j
If Not IsNumeric(arrLeft(i, 1)) Then arrLeft(i, 1) = 0
Next i
'Calc
For i = 1 To UBound(arrCon, 1)
p1 = arrLeft(i, 1)
If p1 > 0 Then
For j = 1 To UBound(arrCon, 2)
p2 = arrTop(1, j)
If p2 > 0 Then
arrCon(i, j) = arrCon(i, j) / arrDec(p1, p2)
End If
Next j
End If
Next i
'Write output
Application.ScreenUpdating = False
rng.Resize(UBound(arrCon, 1), UBound(arrCon, 2)).Value = arrCon
Application.ScreenUpdating = True
'Log end timer
endTime = Timer
Debug.Print (endTime - startTime) & " seconds have passed [VBA]"
End Sub
Bookmarks