Sub Test_vlookup()'test place to see how vlookup will work
L = 1000
Dim wb As Workbook
Dim ws As Worksheet
'set up outputs
Set wb = ActiveWorkbook
Set ws = wb.Sheets("Test_scores")
ws.Range("a1").Value = "Vlookups"
For N = 1 To L
Dim Start As Date
Dim V_Row As String
Dim MS_Data As Range
Dim Bar_data As Range
Dim Vref As Integer
Dim test As String
Dim t As Single
t = Timer
'Worksheets("MS Project Bars Import").Activate
'Set MS_Data = Range("$AX:$BH")
Set MS_Data = Worksheets("MS Project Bars Import").Range("MS_Data")
'Worksheets("Bar Details").Activate
Set Bar_data = Worksheets("Bar Details").Range("Bar_data")
For Vref = 1 To 200
If IsError(Application.VLookup(Vref, MS_Data, 1, False)) Or IsError(Application.VLookup(Vref, Bar_data, 1, False)) Then 'checks if the VRef is used in either the plan or the bar_details sheet to avoid issues with the vlookups
ItemType = "BLANK_Main"
'Debug.Print "Ref: " & Vref & " no data"
Else
Start = Application.WorksheetFunction.VLookup(Vref, MS_Data, 2, False)
finish = Application.WorksheetFunction.VLookup(Vref, MS_Data, 3, False)
BLStart = Application.WorksheetFunction.VLookup(Vref, MS_Data, 4, False)
BLFinish = Application.WorksheetFunction.VLookup(Vref, MS_Data, 5, False)
Complete = Application.WorksheetFunction.VLookup(Vref, MS_Data, 6, False)
Slack = Application.WorksheetFunction.VLookup(Vref, MS_Data, 7, False)
RAG = Application.WorksheetFunction.VLookup(Vref, MS_Data, 8, False)
MS = Application.WorksheetFunction.VLookup(Vref, MS_Data, 9, False)
Critical = Application.WorksheetFunction.VLookup(Vref, MS_Data, 11, False)
'Debug.Print "MS_Data: "
'Debug.Print "Vref: " & Vref & " Start: " & Start & " " & finish & " " & BLStart & " " & BLFinish & " " & Complete & " " & Slack & " " & RAG & " " & MS & " " & Critical
'test = Vref & "-"
V_Row = Application.WorksheetFunction.VLookup(Vref, Bar_data, 6, False)
Hidden_name = Application.WorksheetFunction.VLookup(Vref, Bar_data, 2, False)
Display_name = Application.WorksheetFunction.VLookup(Vref, Bar_data, 3, False)
V_Row_number = Application.WorksheetFunction.VLookup(Vref, Bar_data, 4, False)
Bar_colour = Application.WorksheetFunction.VLookup(Vref, Bar_data, 5, False)
AB = Application.WorksheetFunction.VLookup(Vref, Bar_data, 7, False)
Height_mod = Application.WorksheetFunction.VLookup(Vref, Bar_data, 8, False)
' V_Row = V_Row * 1
'Debug.Print "Bar_data: "
'Debug.Print "ref: " & Vref & "row = " & V_Row & " " & Hidden_anem & " " & Display_name & " " & V_Row_number & " " & Bar_colour & " " & AB & " " & Height_mod
End If
'Debug.Print "Vref: " & Vref & " Start: " & Start & " - " & V_Row
Next Vref
'MsgBox Timer - t
s = Timer - t
Set wb = ActiveWorkbook
Set ws = wb.Sheets("Test_scores")
ws.Range("a" & N + 2).Value = s
tt = tt + s
Next N
ws.Range("a2").Value = tt / L
'MsgBox tt / L
End Sub
Sub Test_match_and_offset()
'test place to see how Match and Offset will work
L = 1000
Dim wb As Workbook
Dim ws As Worksheet
'set up outputs
Set wb = ActiveWorkbook
Set ws = wb.Sheets("Test_scores")
ws.Range("b1").Value = "match and offset"
For N = 1 To L
Dim Start As Date
Dim V_Row As String
Dim MS_Data As Range
Dim Bar_data As Range
Dim Vref As Integer
Dim t As Single
t = Timer
Dim MS_Data_Line_line As String
Dim MS_Data_index As Range
Dim MS_Data_Origin As Range
Dim Bar_data_index As Range
Dim Bar_data_origin As Range
Dim Bar_Data_Line As String
'Worksheets("MS Project Bars Import").Activate ' this doesn't appear to be working
'Set MS_Data = Range("$AX:$BH")
Set MS_Data = Worksheets("MS Project Bars Import").Range("MS_Data") 'why is this not picking up the range???
'Set MS_Data = ActiveWorkbook.Names("MS_Data").RefersToRange
Set MS_Data_index = Range("MS_Data").Columns(1)
Set MS_Data_Origin = Range(Range("MS_Data").Cells(1, 1).Address(0, 0))
'Worksheets("Bar Details").Activate
Set Bar_data = Worksheets("Bar Details").Range("Bar_data")
Set Bar_data_index = Range("Bar_data").Columns(1)
Set Bar_data_origin = Range(Range("Bar_data").Cells(1, 1).Address(0, 0))
'Debug.Print "MS_Data_Origin: " & MS_Data_Origin.Value
'Debug.Print "Bar_Data_Origin: " & Bar_data_origin.Value
For Vref = 1 To 200
If IsError(Application.Match(Vref, MS_Data_index, 0)) Or IsError(Application.Match(Vref, Bar_data_index, 0)) Then 'checks if the VRef is used in either the plan or the bar_details sheet to avoid issues with the vlookups
ItemType = "BLANK_Main"
'Debug.Print "Ref: " & Vref & " no data"
Else
MS_Data_Line = Application.WorksheetFunction.Match(Vref, MS_Data_index, 0) - 1
Start = MS_Data_Origin.Offset(MS_Data_Line, 1).Value
finish = MS_Data_Origin.Offset(MS_Data_Line, 2).Value
BLStart = MS_Data_Origin.Offset(MS_Data_Line, 3).Value
BLFinish = MS_Data_Origin.Offset(MS_Data_Line, 4).Value
Complete = MS_Data_Origin.Offset(MS_Data_Line, 5).Value
Slack = MS_Data_Origin.Offset(MS_Data_Line, 6).Value
RAG = MS_Data_Origin.Offset(MS_Data_Line, 7).Value
MS = MS_Data_Origin.Offset(MS_Data_Line, 8).Value
Critical = MS_Data_Origin.Offset(MS_Data_Line, 10).Value
'Debug.Print "MS_Data: "
'Debug.Print "Ref: " & Vref & " line: " & MS_Data_Line & "start: " & Start & " " & finish & " " & BLStart & " " & BLFinish & " " & Complete & " " & Slack & " " & RAG & " " & MS & " " & Critical
Bar_Data_Line = Application.Match(Vref, Bar_data_index, 0) - 1
V_Row = Bar_data_origin.Offset(Bar_Data_Line, 5).Value
Hidden_name = Bar_data_origin.Offset(Bar_Data_Line, 1).Value
Display_name = Bar_data_origin.Offset(Bar_Data_Line, 2).Value
V_Row_number = Bar_data_origin.Offset(Bar_Data_Line, 3).Value
Bar_colour = Bar_data_origin.Offset(Bar_Data_Line, 4).Value
AB = Bar_data_origin.Offset(Bar_Data_Line, 6).Value
Height_mod = Bar_data_origin.Offset(Bar_Data_Line, 7).Value
'Debug.Print "Bar_data: "
'Debug.Print "Ref: " & Vref & " line: " & Bar_Data_Line & "Y axis " & V_Row & " " & Hidden_anem & " " & Display_name & " " & V_Row_number & " " & Bar_colour & " " & AB & " " & Height_mod
End If
'Debug.Print "Ref: " & Vref & ":" & "line: " & line & ": " & Start & " - " & V_Row
Next Vref
'MsgBox Timer - t
s = Timer - t
Set wb = ActiveWorkbook
Set ws = wb.Sheets("Test_scores")
ws.Range("b" & N + 2).Value = s
tt = tt + s
Next N
ws.Range("b2").Value = tt / L
'MsgBox tt / L
End Sub
Sub Test_match_and_cell()
'test place to see how Match and Cell will work
L = 1000
Dim wb As Workbook
Dim ws As Worksheet
'set up outputs
Set wb = ActiveWorkbook
Set ws = wb.Sheets("Test_scores")
ws.Range("c1").Value = "match and cell"
For N = 1 To L
Dim Start As Date
Dim V_Row As String
Dim MS_Data As Range
Dim Bar_data As Range
Dim Vref As Integer
Dim t As Single
t = Timer
Dim MS_Data_Line_line As String
Dim MS_Data_index As Range
Dim MS_Data_Origin As Range
Dim Bar_data_index As Range
Dim Bar_data_origin As Range
Dim Bar_Data_Line As String
'Worksheets("MS Project Bars Import").Activate ' this doesn't appear to be working
'Set MS_Data = Range("$AX:$BH")
Set MS_Data = Worksheets("MS Project Bars Import").Range("MS_Data") 'why is this not picking up the range???
'Set MS_Data = ActiveWorkbook.Names("MS_Data").RefersToRange
'Set MS_Data_index = Range("MS_Data").Columns(1)
'Set MS_Data_Origin = Range(Range("MS_Data").Cells(1, 1).Address(0, 0))
'Worksheets("Bar Details").Activate
Set Bar_data = Worksheets("Bar Details").Range("Bar_data")
'Set Bar_data_index = Range("Bar_data").Columns(1)
'Set Bar_data_origin = Range(Range("Bar_data").Cells(1, 1).Address(0, 0))
'Debug.Print "MS_Data_Origin: " & MS_Data_Origin.Value
'Debug.Print "Bar_Data_Origin: " & Bar_data_origin.Value
For Vref = 1 To 200
If IsError(Application.Match(Vref, MS_Data.Columns(1), 0)) Or IsError(Application.Match(Vref, Bar_data.Columns(1), 0)) Then 'checks if the VRef is used in either the plan or the bar_details sheet to avoid issues with the vlookups
ItemType = "BLANK_Main"
'Debug.Print "Ref: " & Vref & " no data"
Else
MS_Data_Line = Application.Match(Vref, MS_Data.Columns(1), 0) ' finds the row for VRef
Start = MS_Data.Cells(MS_Data_Line, 2) 'MS_Data_Origin.Offset(MS_Data_Line, 1).Value
finish = MS_Data.Cells(MS_Data_Line, 3) 'MS_Data_Origin.Offset(MS_Data_Line, 2).Value
BLStart = MS_Data.Cells(MS_Data_Line, 4) 'MS_Data_Origin.Offset(MS_Data_Line, 3).Value
BLFinish = MS_Data.Cells(MS_Data_Line, 5) 'MS_Data_Origin.Offset(MS_Data_Line, 4).Value
Complete = MS_Data.Cells(MS_Data_Line, 6) 'MS_Data_Origin.Offset(MS_Data_Line, 5).Value
Slack = MS_Data.Cells(MS_Data_Line, 7) 'MS_Data_Origin.Offset(MS_Data_Line, 6).Value
RAG = MS_Data.Cells(MS_Data_Line, 8) 'MS_Data_Origin.Offset(MS_Data_Line, 7).Value
MS = MS_Data.Cells(MS_Data_Line, 9) 'MS_Data_Origin.Offset(MS_Data_Line, 8).Value
Critical = MS_Data.Cells(MS_Data_Line, 11) 'MS_Data_Origin.Offset(MS_Data_Line, 10).Value
'Debug.Print "MS_Data: "
'Debug.Print "Ref: " & Vref & " line: " & MS_Data_Line & "start: " & Start & " " & finish & " " & BLStart & " " & BLFinish & " " & Complete & " " & Slack & " " & RAG & " " & MS & " " & Critical
Bar_Data_Line = Application.Match(Vref, Bar_data.Columns(1), 0)
V_Row = Bar_data.Cells(Bar_Data_Line, 6) 'Bar_data_origin.Offset(Bar_Data_Line, 5).Value
Hidden_name = Bar_data.Cells(Bar_Data_Line, 2) 'Bar_data_origin.Offset(Bar_Data_Line, 1).Value
Display_name = Bar_data.Cells(Bar_Data_Line, 3) 'Bar_data_origin.Offset(Bar_Data_Line, 2).Value
V_Row_number = Bar_data.Cells(Bar_Data_Line, 4) 'Bar_data_origin.Offset(Bar_Data_Line, 3).Value
Bar_colour = Bar_data.Cells(Bar_Data_Line, 5) 'Bar_data_origin.Offset(Bar_Data_Line, 4).Value
AB = Bar_data.Cells(Bar_Data_Line, 7) 'Bar_data_origin.Offset(Bar_Data_Line, 6).Value
Height_mod = Bar_data.Cells(Bar_Data_Line, 8) 'Bar_data_origin.Offset(Bar_Data_Line, 7).Value
'Debug.Print "Bar_data: "
'Debug.Print "Ref: " & Vref & " line: " & Bar_Data_Line & " Y axis " & V_Row & " " & Hidden_anem & " " & Display_name & " " & V_Row_number & " " & Bar_colour & " " & AB & " " & Height_mod
End If
'Debug.Print "Ref: " & Vref & ":" & "line: " & line & ": " & Start & " - " & V_Row
Next Vref
'MsgBox Timer - t
s = Timer - t
Set wb = ActiveWorkbook
Set ws = wb.Sheets("Test_scores")
ws.Range("c" & N + 2).Value = s
tt = tt + s
Next N
ws.Range("c2").Value = tt / L
'MsgBox tt / L
End Sub
Sub Test_Array_match_and_cell()
'test place to see how Match and array will work
L = 50
Dim wb As Workbook
Dim ws As Worksheet
'set up outputs
Set wb = ActiveWorkbook
Set ws = wb.Sheets("Test_scores")
ws.Range("d1").Value = "Array match and cell"
For N = 1 To L
Dim Start As Date
Dim V_Row As String
Dim MS_Data As Range
Dim Bar_data As Range
Dim Vref As Integer
Dim t As Single
t = Timer
Dim MS_Data_Line As Long
Dim MS_Data_index As Range
Dim MS_Data_Origin As Range
Dim Bar_data_index As Range
Dim Bar_data_origin As Range
Dim Bar_Data_Line As Long
Dim MS_Data_Array As Variant
'Worksheets("MS Project Bars Import").Activate ' this doesn't appear to be working
'Set MS_Data = Range("$AX:$BH")
Set MS_Data = Worksheets("MS Project Bars Import").Range("MS_Data") 'why is this not picking up the range???
MS_Data_Array = MS_Data.Value
'Set MS_Data = ActiveWorkbook.Names("MS_Data").RefersToRange
'Set MS_Data_index = Range("MS_Data").Columns(1)
'Set MS_Data_Origin = Range(Range("MS_Data").Cells(1, 1).Address(0, 0))
'Worksheets("Bar Details").Activate
Set Bar_data = Worksheets("Bar Details").Range("Bar_data")
'Set Bar_data_index = Range("Bar_data").Columns(1)
'Set Bar_data_origin = Range(Range("Bar_data").Cells(1, 1).Address(0, 0))
'Debug.Print "MS_Data_Origin: " & MS_Data_Origin.Value
'Debug.Print "Bar_Data_Origin: " & Bar_data_origin.Value
For Vref = 1 To 200
If IsError(Application.Match(Vref, MS_Data.Columns(1), 0)) Or IsError(Application.Match(Vref, Bar_data.Columns(1), 0)) Then 'checks if the VRef is used in either the plan or the bar_details sheet to avoid issues with the vlookups
ItemType = "BLANK_Main"
'Debug.Print "Ref: " & Vref & " no data"
Else
MS_Data_Line = Application.Match(Vref, Application.Index(MS_Data_Array, , 1), 0) ' finds the row for VRef
Start = MS_Data_Array(MS_Data_Line, 2) 'MS_Data_Origin.Offset(MS_Data_Line, 1).Value
finish = MS_Data_Array(MS_Data_Line, 3) 'MS_Data_Origin.Offset(MS_Data_Line, 2).Value
BLStart = MS_Data_Array(MS_Data_Line, 4) 'MS_Data_Origin.Offset(MS_Data_Line, 3).Value
BLFinish = MS_Data_Array(MS_Data_Line, 5) 'MS_Data_Origin.Offset(MS_Data_Line, 4).Value
Complete = MS_Data_Array(MS_Data_Line, 6) 'MS_Data_Origin.Offset(MS_Data_Line, 5).Value
Slack = MS_Data_Array(MS_Data_Line, 7) 'MS_Data_Origin.Offset(MS_Data_Line, 6).Value
RAG = MS_Data_Array(MS_Data_Line, 8) 'MS_Data_Origin.Offset(MS_Data_Line, 7).Value
MS = MS_Data_Array(MS_Data_Line, 9) 'MS_Data_Origin.Offset(MS_Data_Line, 8).Value
Critical = MS_Data_Array(MS_Data_Line, 11) 'MS_Data_Origin.Offset(MS_Data_Line, 10).Value
'Debug.Print "MS_Data: "
'Debug.Print "Ref: " & Vref & " line: " & MS_Data_Line & "start: " & Start & " " & finish & " " & BLStart & " " & BLFinish & " " & Complete & " " & Slack & " " & RAG & " " & MS & " " & Critical
Bar_Data_Line = Application.Match(Vref, Bar_data.Columns(1), 0)
V_Row = Bar_data.Cells(Bar_Data_Line, 6) 'Bar_data_origin.Offset(Bar_Data_Line, 5).Value
Hidden_name = Bar_data.Cells(Bar_Data_Line, 2) 'Bar_data_origin.Offset(Bar_Data_Line, 1).Value
Display_name = Bar_data.Cells(Bar_Data_Line, 3) 'Bar_data_origin.Offset(Bar_Data_Line, 2).Value
V_Row_number = Bar_data.Cells(Bar_Data_Line, 4) 'Bar_data_origin.Offset(Bar_Data_Line, 3).Value
Bar_colour = Bar_data.Cells(Bar_Data_Line, 5) 'Bar_data_origin.Offset(Bar_Data_Line, 4).Value
AB = Bar_data.Cells(Bar_Data_Line, 7) 'Bar_data_origin.Offset(Bar_Data_Line, 6).Value
Height_mod = Bar_data.Cells(Bar_Data_Line, 8) 'Bar_data_origin.Offset(Bar_Data_Line, 7).Value
'Debug.Print "Bar_data: "
'Debug.Print "Ref: " & Vref & " line: " & Bar_Data_Line & " Y axis " & V_Row & " " & Hidden_anem & " " & Display_name & " " & V_Row_number & " " & Bar_colour & " " & AB & " " & Height_mod
End If
'Debug.Print "Ref: " & Vref & ":" & "line: " & line & ": " & Start & " - " & V_Row
Next Vref
'MsgBox Timer - t
s = Timer - t
Set wb = ActiveWorkbook
Set ws = wb.Sheets("Test_scores")
ws.Range("d" & N + 2).Value = s
tt = tt + s
Next N
ws.Range("d2").Value = tt / L
'MsgBox tt / L
End Sub