Evening!
So, I'm trying to make a macro that will search multiple workbooks for a date defined from a user input box, select that cell, offset the selection by 3 columns and resize with 14 rows.
The reason for this is that every day I get 1 staffing report from 6 different bases (effectively 6 files) and have to compare the info from yesterday with the updated info from today.
So what I get are 6 files that look something like what's below. A2 and downwards are the dates I want to search for, while D2 and downwards contain the numbers I want.
The .Resize is because I need the info from the date I search from and the 2 following weeks (+14 rows).
Report ex.
A B C D E
1| x x x 1 x
2| x x x 2 x
3| x x x 3 x
4| x x x 4 x
5| x x x 5 x
I've already set up an Excel sheet to store and compare the extracted info, but I'm having some issues with efficiently extracting it from multiple rows in the reports, to 1 row in the "master".
The example below is for 1 report only, but I'm thinking that if I get it to work, I can just add the path and name variables, then add the code necessary.
What I got so far:
I'm getting a bit different errors depending on where I make changes, but I'm hoping you guys could give me some pointers to where I can begin.Option Explicit
Sub SearchARN()
Application.ScreenUpdating = False
Dim ARNsource As Workbook
Dim MasterWB As Workbook
Dim MasterSH As Worksheet
Set MasterWB = ActiveWorkbook
Set MasterSH = MasterWB.Sheets("Sheet1")
Set ARNsource = Workbooks.Open("C:\Users\"xxxxx"\Desktop\Macro\Reports\Nightshift_ARN.xlsx")
' D2 here is for testing only, later it should be the "date"/value stored from the user input box
With ARNsource.Sheets("Sheet1").Range("D2").Resize(14, 0)
.Select.Copy
End With
' The range defined is where I need the extracted data to go, for it to work with the comparison formula in the "master"
' I've tried using .Transpose to paste from say "D2:D16" to "C33:Q33", but for me that only created a whole new set of issues
With MasterSH.Range("C33:Q33").PasteSpecial
End With
ARNsource.Close SaveChanges:=False
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
Thanks in advance!
Bookmarks