Need help expanding this code to make it do the following:
1. Start w/ "RULE-Table" sheet,
2. Take note of "TODAY" date,
3. LOOKUP date in "RULE-table"
4. Locate Coordinates found in Col D of RULE-Table,
5. LOOKUP the data that resides in those Coordinates on the "PRODUCTION" sheet & COPY
6. PASTE data into "REPORT" tab C2 and E2.
Here's an example to help visualize:
Code will do everything it needs to do within an Undisclosed OPEN file with several sheets.
The reason the Workbook file name is undisclosed/undefined is because the file name will vary based on clients, so I don't want the code to be limited to look for a specific filename.
*The sheet names within this OPEN client file will always have the same names.
The sheet called: "RULE-Table" holds coordinates based upon "TODAY's" computer date.
For example: If today is JAN 4, the desired coordinates to pull data from are "B5" and "D10" from the "PRODUCTION" sheet.
"RULE-Table" sheet
A......B.........C................D.......
Row1.DAY....WK RANGE....QTR RANGE
2......1/1.......1...............B2,D7
3......1/2.......1...............B3,D8
4......1/3.......1...............B4,D9
5......1/4.......1...............B5,D10
6......1/5.......1...............B6,D11
Since today is 1/4, its rules say go to B2 and D10 of the PRODUCTION tab and collect the data
"PRODUCTION" (data source) sheet (within the same open file)
A.......B......C....D....E....F...
Row1..Header..Hdr..Hdr..Hdr..Hdr.
2.......2.................................
3.......14...............................
4.......13...............................
5.......20...............................
6.......62..............................
7....................76.................
8...................184................
9...................375................
10.................410................
11.................525...............
Last, the collected data from those 2 coordinates should always get pasted onto the "REPORT" tab
into C2 and E2 in this example.
"REPORT" (destination) sheet (within the same open file)
A........B.........C.....D....E.....
Row1..Header..Hdr..Hdr..Hdr..
2...................20........410......
Sub LookupRulesCopyPasteResults()
' -----------------------------------------------------------------------------------------
' Define variables
' -----------------------------------------------------------------------------------------
Dim strFilename As String
Dim strWorkbookName As String
Dim objInputWB As Workbook
Dim objExtractWB As Workbook
Dim oWB As Workbook, oWS As Worksheet
Dim lngLastRow As Long, bFound As Boolean
' -----------------------------------------------------------------------------------------
' Find workbook with Worksheet named "RULE-Table" Worksheet
' -----------------------------------------------------------------------------------------
For Each oWB In Workbooks ' cycling through each open workbook
For Each oWS In oWB.Sheets ' cycling through each sheet of each workbook
If oWS.Name = "RULE-Table" Then ' comparing the sheet name to find the one we are looking for
Set objInputWB = oWB
bFound = True
End If
If bFound Then Exit For
Next oWS
If bFound Then Exit For
Next oWB
Set oWB = Nothing
' -----------------------------------------------------------------------------------------
' Advise user and terminate program if we cannot find the approprate workbook.
' -----------------------------------------------------------------------------------------
If Not bFound Then
MsgBox Prompt:="Unable to find data's destination 'RULE-Table', Please make sure your Client WB is open - terminating this transfer attempt!", _
Buttons:=vbCrtical, _
Title:="Export"
Exit Sub
End If
' -----------------------------------------------------------------------------------------
' Lookup TODAY date (based on Computer's date)
' -----------------------------------------------------------------------------------------
' xxxxx
' -----------------------------------------------------------------------------------------
' Lookup that date on the "RULE-Table" tab
' -----------------------------------------------------------------------------------------
Sheets("RULE-Table").Select
' xxxxx
' -----------------------------------------------------------------------------------------
' Take note of the Coordinates found in Column D of the "RULE-Table" tab
' -----------------------------------------------------------------------------------------
' xxxxx
' -----------------------------------------------------------------------------------------
' Lookup data residing in those Coordinates on the "PRODUCTION" tab & COPY those 2 cells C2 & E2
' -----------------------------------------------------------------------------------------
Sheets("PRODUCTION").Select
Range("C2").Select
Selection.Copy
Sheets("REPORTS").Select
Range("E2").Select
Selection.Copy
' xxxxx
' -----------------------------------------------------------------------------------------
' Last, PASTE that data into Cell "C2" and Cell "E2" of the "REPORT" tab
' -----------------------------------------------------------------------------------------
Sheets("REPORTS").Select
Range("C2").Select
ActiveSheet.Paste
Range("A3").Select
Range("E2").Select
ActiveSheet.Paste
Range("E2").Select
' xxxxx
' -----------------------------------------------------------------------------------------
' Tell the Analyst that the Client's Data was Successfully Transferred to the Report
' -----------------------------------------------------------------------------------------
MsgBox "Transfer of Production Data to Report is Complete!"
End Sub
Bookmarks