I have a table with five columns: Project #, Phase #, $$$$, Completion % M1, Completion % M2
I am trying to write a code that takes the transfers Completion % M2 to Completion % M1 when the Data gets updated. The data gets updated every month and sometimes project numbers drop off or phases are added to projects.
What I am struggling to figure out is if I can use a multi-dimensional array to store the data, then sort it to match the new data and update the corresponding cells.
Option Explicit
'Public variable to define date at woorkbook initialization (start-up)
Public inDate As Date
'Public variable to define table length at woorkbook initialization (start-up)
Public intTotalRows As Long
'Public variables to define PM % complete arrays
Public strArray0() As Variant
Sub LoadArray2()
Dim i As Long
Dim n As Long
'Set Array element length
ReDim strArray0(intTotalRows, 3)
'Collect PM enetered % complete information
For i = 1 To intTotalRows
strArray0(i, 1) = Worksheets("Stream 3 Month Financial Review").Cells(i + 1, 1).Value
strArray0(i, 2) = Worksheets("Stream 3 Month Financial Review").Cells(i + 1, 2).Value
strArray0(i, 3) = Worksheets("Stream 3 Month Financial Review").Cells(i + 1, 5).Value
Next
End Sub
Private Sub Workbook_Open()
' Get previous data pull date prior to pull updating (Get Data)
inDate = Worksheets("Data Pull Date").Range("F2")
Debug.Print ("inDate " & inDate)
Dim tbl1 As ListObject
' Count # of Rows in Raw Data Table prior to pull updating (Get Data)
Set tbl1 = Worksheets("Raw Data (Transformed)").ListObjects("Stream_Data_Centers_3_Month_Review")
intTotalRows = tbl1.Range.Rows.Count - 1
Debug.Print ("intTotalRows " & intTotalRows)
End Sub
Private Sub Worksheet_TableUpdate(ByVal Target As TableObject)
Dim curDate As Date
Dim curTotalRows As Long
'Get current data pull date after pull updating (Get Data)
curDate = Worksheets("Data Pull Date").Range("F2")
Debug.Print ("curDate " & curDate)
'Update PM entered % Complete if curDate is month after inDate
If Month(curDate) = Month(inDate) Then
'nothing
Else
LoadArray2
'Shift PM % Complete value over to left, Clear Last Row
For i = 1 To intTotalRows
Worksheets("Stream 3 Month Financial Review").Cells(i + 1, 4).Value = strArray1(i)
Next
End If
End Sub
I need a code to take strArray0(i, 3) and populate column 4 with the data if strArray0(i, 1) and strArray0(i, 2) match the value is columns 1 and 2.
I decided to add a column in the transformed data to create a UID for each line. So now I just need to match strArray0(i, 1) to a value in column 1.