logandiana
Board Regular
- Joined
- Feb 21, 2017
- Messages
- 107
I have one workbook that does some stuff, then opens another workbook, copies some stuff to it, updates some pivot tables, then saves and closes it.
The second workbook has 3 tabs, but only 1 visible (PivData)
When I run the code, everything seems to be working as it should, but then I go out to look at the finished product.
After the code has run, when I open the second worksheet (RYGmonthly), there are now two tabs visible (PivData) and (DOWNLOADS), with the latter selected.
I can't find what in the code is telling the second worksheet to unhide and select the (DOWNLOADS) tab.
This is a complete mystery to me.
The second workbook has 3 tabs, but only 1 visible (PivData)
When I run the code, everything seems to be working as it should, but then I go out to look at the finished product.
After the code has run, when I open the second worksheet (RYGmonthly), there are now two tabs visible (PivData) and (DOWNLOADS), with the latter selected.
I can't find what in the code is telling the second worksheet to unhide and select the (DOWNLOADS) tab.
This is a complete mystery to me.
Code:
[Sub DayOverDay()
Set RYG = ThisWorkbook
Set DLX = RYG.Sheets("DLX")
Set DOD = Workbooks.Open("\\RYG_Monthly.xlsx")
Set PIV = DOD.Sheets("PivData")
Set DWN = DOD.Sheets("DOWNLOADS")
Set RAW = DOD.Sheets("RawData")
RAW.Columns("A:C").ClearContents
LR8 = PIV.Cells(Rows.Count, 1).End(xlUp).Row
PIV.Range("A2:I" & LR8).ClearContents
LR5 = DLX.Cells(Rows.Count, 1).End(xlUp).Row
DLX.Range("A1:H" & LR5).Copy
RAW.Range("A1").PasteSpecial xlPasteAll
RAW.Columns("D:G").Delete
RAW.Columns("B").Delete
LR6 = RAW.Cells(Rows.Count, 1).End(xlUp).Row
RAW.Range("A1:C" & LR6).Copy
LR7 = DWN.Cells(Rows.Count, 1).End(xlUp).Row
DWN.Range("A" & LR7 + 1).PasteSpecial xlPasteAll
DWN.Columns("A:C").RemoveDuplicates Columns:=Array(1, 2, 3), Header:=xlYes
LR7 = DWN.Cells(Rows.Count, 1).End(xlUp).Row
DWN.Range("A2:C" & LR7).Copy
PIV.Range("A2").PasteSpecial xlPasteAll
LR8 = PIV.Cells(Rows.Count, 1).End(xlUp).Row
PIV.Range("D2:D" & LR8).FormulaR1C1 = "=INT(RC[-2])"
PIV.Range("E2:E" & LR8).FormulaR1C1 = "=TEXT(RC[-3],""mmmm"")"
PIV.Range("F2:F" & LR8).FormulaR1C1 = "=TEXT(RC[-4],""dddd"")"
PIV.Range("G2:G" & LR8).FormulaR1C1 = "=WEEKNUM(RC[-5])"
PIV.Range("H2:H" & LR8).FormulaR1C1 = "=RC[-6]-RC[-4]"
PIV.Range("I2:I" & LR8).FormulaR1C1 = "=HOUR(RC[-1])"
PIV.PivotTables("PivotTable3").PivotCache.Refresh
PIV.PivotTables("PivotTable3").PivotFields("Date").ShowDetail = False
PIV.PivotTables("PivotTable3").PivotFields("Week").ShowDetail = False
PIV.PivotTables("PivotTable3").PivotFields("Month").ShowDetail = False
DOD.Save
DOD.Close
End Sub