Sub test()
ts1 = Timer()
Dim Ary As Variant
Dim i As Long
Dim Dic As Object
Set Dic = CreateObject("Scripting.dictionary")
Dim outr()
barray = Array("A2", "B2", "C2", "D2", "E2", "F2", "G2", "H2", "I2", "J2", "K2", "L2", "M2", "N2", "O2", "P2", "Q2", "R2", "S2", "T2", "U2", "V2", "W2", "X2", "Y2", "Z2", "AA2", "AB2", "AC2", "AD2", "AE2", "AF2")
' first convert the column letters in barray to column numbers
ReDim outr(1 To 102835, 1 To UBound(barray) + 1)
For i = 0 To UBound(barray)
tt = Len(barray(i))
If tt = 2 Then
outr(2, i + 1) = Asc(Left(barray(i), 1)) - 64 ' column Number
outr(1, i + 1) = barray(i) ' Column Letter
Else
outr(2, i + 1) = Asc(Mid(barray(i), 2, 1)) - 64 + 26
outr(1, i + 1) = barray(i)
End If
Next i
''''''''''''''''''''''''''''
With Sheets("Baseline Weights")
Ary = .Range("b5:F167") ' load all the bae line weights into a variant array
For i = 1 To UBound(Ary)
Dic(Ary(i, 1)) = Ary(i, 5) ' add them all to the dictionary
Next i
End With
''''''''''''''''''''''''''''''
With Sheets("Geomapping Data")
datr = .Range("A1:At102835") ' load all the data into a variant array
End With
With Sheets("Geomapping Data")
.Range("ba1:Ct102835") = "" ' expand to column Ca (79)
datout = .Range("ba1:Ct102835") ' load all the data into a variant array
For j = 1 To UBound(barray) + 1 ' loop through all the columns
head = datr(1, outr(2, j)) ' pick up header from row 1
datout(1, outr(2, j)) = head
For k = 2 To UBound(datr, 1) ' loop through all the rows
ditem = head & datr(k, outr(2, j))
If Dic.Exists(ditem) Then
datout(k, outr(2, j)) = Dic(ditem) + 1
Else
datout(k, outr(2, j)) = 1
End If
Next k
Next j
' .Range("ba1:Ct102835") = datout
' load the square roots from column CB
commsqurts = .Range("da1:da102835")
domsqurts = .Range("db1:db102835")
instsqurts = .Range("dc1:dc102835")
commtestexp = .Range("Al1:al102835")
domtestexp = .Range("An1:an102835")
insttestexp = .Range("Ap1:ap102835")
testexp = .Range("As1:as102835")
' Ba is column 53
For r = 2 To 102835
' Note I have to change the addressing here because the variant array datout starts at column Aq i.e columns 42
datout(r, 99 - 53) = datout(r, 54 - 53) * datout(r, 57 - 53) * datout(r, 58 - 53) * datout(r, 59 - 53) * datout(r, 60 - 53) * datout(r, 61 - 53) * datout(r, 62 - 53) * datout(r, 63 - 53) * datout(r, 64 - 53) * datout(r, 65 - 53) * datout(r, 66 - 53) * datout(r, 67 - 53) * datout(r, 68 - 53) * datout(r, 69 - 53) * datout(r, 70 - 53) * datout(r, 71 - 53) * datout(r, 72 - 53) * datout(r, 73 - 53) * datout(r, 74 - 53) * datout(r, 75 - 53) * datout(r, 76 - 53) * datout(r, 77 - 53) * datout(r, 78 - 53) * datout(r, 79 - 53) * datout(r, 80 - 53) * datout(r, 81 - 53) * datout(r, 82 - 53) * datout(r, 83 - 53) * datout(r, 84 - 53) * datout(r, 85 - 53)
commtestexp(r, 1) = (231859.13 * datout(r, 99 - 53) * datout(r, 55 - 53) * commsqurts(r, 1))
domtestexp(r, 1) = (231859.13 * datout(r, 99 - 53) * domsqurts(r, 1))
insttestexp(r, 1) = (231859.13 * datout(r, 99 - 53) * datout(r, 56 - 53) * instsqurts(r, 1))
testexp(r, 1) = (commtestexp(r, 1) + domtestexp(r, 1) + insttestexp(r, 1))
Next r
.Range("ba1:Ct102835") = datout
.Range("Al1:al102835") = commtestexp
.Range("An1:an102835") = domtestexp
.Range("Ap1:ap102835") = insttestexp
.Range("As1:as102835") = testexp
End With
' Table of differences
Worksheets("Baseline Weights").Range("n7") = Application.Sum(Sheets("Geomapping Data").Columns("AS:AS"))
Worksheets("Baseline Weights").Range("n15") = Application.Sum(Sheets("Geomapping Data").Columns("AL:AL"))
Worksheets("Baseline Weights").Range("n16") = Application.Sum(Sheets("Geomapping Data").Columns("AN:AN"))
Worksheets("Baseline Weights").Range("n17") = Application.Sum(Sheets("Geomapping Data").Columns("AP:AP"))
Worksheets("Baseline Weights").Range("n9") = Application.WorksheetFunction.SumIf(Sheets("Geomapping Data").Columns("AT:AT"), 1, Sheets("Geomapping Data").Columns("AS:AS"))
Worksheets("Baseline Weights").Range("n10") = Application.WorksheetFunction.SumIf(Sheets("Geomapping Data").Columns("AT:AT"), 2, Sheets("Geomapping Data").Columns("AS:AS"))
Worksheets("Baseline Weights").Range("n11") = Application.WorksheetFunction.SumIf(Sheets("Geomapping Data").Columns("AT:AT"), 3, Sheets("Geomapping Data").Columns("AS:AS"))
Worksheets("Baseline Weights").Range("n12") = Application.WorksheetFunction.SumIf(Sheets("Geomapping Data").Columns("AT:AT"), 4, Sheets("Geomapping Data").Columns("AS:AS"))
Worksheets("Baseline Weights").Range("n13") = Application.WorksheetFunction.SumIf(Sheets("Geomapping Data").Columns("AT:AT"), 5, Sheets("Geomapping Data").Columns("AS:AS"))
Worksheets("Baseline Weights").Range("n19") = Application.WorksheetFunction.RSq(Sheets("Data").Columns("AN:AN"), Sheets("Data").Columns("AI:AI"))
' Data for accuracy
Dim Ary2 As Variant
Dim i2 As Long
Dim Dic2 As Object
Set Dic2 = CreateObject("Scripting.dictionary")
Dim outr2()
barray = Array("A2", "F2", "G2", "H2", "I2", "J2", "K2", "L2", "M2", "N2", "O2", "P2", "Q2", "R2", "S2", "T2", "U2", "V2", "W2", "X2", "Y2", "Z2", "AA2", "AB2", "AC2", "AD2", "AE2", "AF2", "AG2", "AH2")
' first convert the column letters in barray to column numbers
ReDim outr2(1 To 1226, 1 To UBound(barray) + 1)
For i2 = 0 To UBound(barray)
tt = Len(barray(i2))
If tt = 2 Then
outr2(2, i2 + 1) = Asc(Left(barray(i2), 1)) - 64 ' column Number
outr2(1, i2 + 1) = barray(i2) ' Column Letter
Else
outr2(2, i2 + 1) = Asc(Mid(barray(i2), 2, 1)) - 64 + 26
outr2(1, i2 + 1) = barray(i2)
End If
Next i2
''''''''''''''''''''''''''''
With Sheets("Baseline Weights")
Ary2 = .Range("b5:F167") ' load all the bae line weights into a variant array
For i2 = 1 To UBound(Ary2)
Dic(Ary2(i2, 1)) = Ary2(i2, 5) ' add them all to the dictionary
Next i2
End With
''''''''''''''''''''''''''''''
With Sheets("Data")
datr = .Range("A1:Am1226") ' load all the data into a variant array
End With
With Sheets("Data")
.Range("Aq1:Ca1226") = "" ' expand to column Ca (79)
datout = .Range("Aq1:Ca1226") ' load all the data into a variant array
For j = 1 To UBound(barray) + 1 ' loop through all the columns
head = datr(1, outr(2, j)) ' pick up header from row 1
datout(1, outr2(2, j)) = head
For k = 2 To UBound(datr, 1) ' loop through all the rows
ditem = head & datr(k, outr(2, j))
If Dic2.Exists(ditem) Then
datout(k, outr2(2, j)) = Dic2(ditem) + 1
Else
datout(k, outr2(2, j)) = 1
End If
Next k
Next j
' .Range("Aq1:bx1226") = datout
' load the square roots from column CB
squrts = .Range("cb1:cb1226")
testexp = .Range("An1:ao1226")
' Aq is column 42
For r = 2 To 1226
' Note I have to change the addressing here because the variant array datout starts at column Aq i.e columns 42
datout(r, 79 - 42) = datout(r, 43 - 42) * datout(r, 48 - 42) * datout(r, 49 - 42) * datout(r, 50 - 42) * datout(r, 51 - 42) * datout(r, 52 - 42) * datout(r, 53 - 42) * datout(r, 54 - 42) * datout(r, 55 - 42) * datout(r, 56 - 42) * datout(r, 57 - 42) * datout(r, 58 - 42) * datout(r, 59 - 42) * datout(r, 60 - 42) * datout(r, 61 - 42) * datout(r, 62 - 42) * datout(r, 63 - 42) * datout(r, 64 - 42) * datout(r, 65 - 42) * datout(r, 66 - 42) * datout(r, 67 - 42) * datout(r, 68 - 42) * datout(r, 69 - 42) * datout(r, 70 - 42) * datout(r, 71 - 42) * datout(r, 72 - 42) * datout(r, 73 - 42) * datout(r, 74 - 42) * datout(r, 75 - 42) * datout(r, 76 - 42)
testexp(r, 1) = (231859.13 * datout(r, 79 - 42) * squrts(r, 1))
testexp(r, 2) = testexp(r, 1) / datr(r, 35)
Next r
.Range("Aq1:ca1226") = datout
.Range("An1:ao1226") = testexp
End With
Worksheets("Baseline Weights").Range("n19") = Application.WorksheetFunction.RSq(Sheets("Data").Columns("AN:AN"), Sheets("Data").Columns("AI:AI"))
ts2 = Timer()
MsgBox 1000 * (ts2 - ts1) & "milliseconds"
'Range(Cells(1, 1), Cells(10, UBound(barray))) = outr
End Sub