I have project spreadsheets that list Projected hours each employee is expected to work per month.
I have a master spreadsheet that has tabs for each quarter. Each tab has the project number across the top, and each employee down the left.
I am trying to make a Macro that will open each project spreadsheet, find the proper column for that project in the Master, then add the hours each employee worked that quarter from the project sheet to the master sheet.
The section of code to open the spreadsheets works fine, it's legacy code from someone that knew what they were doing. The search finds the correct project, but it tells me it is column 34, but AJ is 36. No idea what causes that discrepancy. Have not yet written the code to copy over the hours yet.
I have a master spreadsheet that has tabs for each quarter. Each tab has the project number across the top, and each employee down the left.
I am trying to make a Macro that will open each project spreadsheet, find the proper column for that project in the Master, then add the hours each employee worked that quarter from the project sheet to the master sheet.
The section of code to open the spreadsheets works fine, it's legacy code from someone that knew what they were doing. The search finds the correct project, but it tells me it is column 34, but AJ is 36. No idea what causes that discrepancy. Have not yet written the code to copy over the hours yet.
Code:
Sub Main()
On Error Resume Next
Application.DisplayAlerts = False
Dim MyFodler As String
Dim MyFile As String
Dim PFile As Workbook
Workbooks.Open ("C:\Users\RMQ2.xlsx")
MyFolder = "C:\Users\Janice\Roast"
MyFile = Dir(MyFolder & "\*.xlsx")
Do While MyFile <> ""
Workbooks.Open FileName:=MyFolder & "\" & MyFile
MyFile = Dir
PFile = Workbook.Active
Dim Project As String
Project = Workbooks(PFile).Range("C1")
Workbooks("RMQ2.xlsx").Activate
Rows("4:4").Select
'Row of the master sheet that has the project numbers
Selection.Find(What:=Project, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
Dim iCol As Integer
iCol = ActiveCell.Column
'Gives the column to paste in later.
MsgBox iCol, vbInformation
'Check that it's giving the right one. Seems not.
'Following code is still very raw, not working.
Dim lRow As Long
Dim iRow As Long
Dim MRow As Long
Dim Rng As Range
'somehow get it to use the names in PFile column B, starting at row 54 to row 145-ish to match the RMQ2 name and math from PFile to RMQ2.
For iRow = 54 To lRow Step 1
Next iRow
Workbooks(RMQ2.xlsx).Activate
Loop
MsgBox "Finshed...", vbInformation
End Sub