Hi all
The below code works, but the arrays for filtering data will only accept two variables to filter on. Am I doing something wrong? I would love to be able to put all 4 variables in the array and get rid of the excess code.
Please refer to the sections below: 'Filter data on 1002 Based SOF workbook (part 1) & (part 2)
Thanks in advance for the help!
The below code works, but the arrays for filtering data will only accept two variables to filter on. Am I doing something wrong? I would love to be able to put all 4 variables in the array and get rid of the excess code.
Please refer to the sections below: 'Filter data on 1002 Based SOF workbook (part 1) & (part 2)
Thanks in advance for the help!
Code:
Sub FilterCopySOF()
'Define variables
Dim wbBudget As Workbook 'Budget & Execution Tool workbook
Dim wbSOF As Workbook '1002_Based_SOF workbook located in MDA Daily Reports
Dim LastDate As Date 'Last modified date of 1002_Based_SOF
Dim LastRow As Long 'Last row of SOF DAI worksheet in the GM 1-N Budget & Execution Tool workbook
'Delete old data from SOF DAI worksheet and turn off filter
Application.CutCopyMode = False
Set wbBudget = ActiveWorkbook
With wbBudget.Sheets("SOF DAI")
.Range("A2", .Cells(.Rows.Count, .Columns.Count)).Clear
End With
wbBudget.Sheets("SOF DAI").AutoFilterMode = False
'Open and Activate the 1002 Based SOF from the server
Set wbSOF = Workbooks.Open("xxx/1002_Based_SoF.xlsx")
wbSOF.Activate
'Retrieve Date of 1002 Based SOF
LastDate = FileDateTime("xxx/1002_Based_SoF.xlsx")
wbBudget.Sheets("Report Set-Up").Range("Date_SOF").Value = LastDate
'Filter data on 1002 Based SOF workbook (part 1)
wbSOF.Sheets(1).Select
Range("A1").AutoFilter
Range("A1").AutoFilter Field:=2, Criteria1:=Array("2015", "2016"), Operator:=xlFilterValues
Range("A1").AutoFilter Field:=3, Criteria1:=Array("=2P_SO08*", "=X3_*"), Operator:=xlFilterValues
'Copy and Paste the 1002 Based SOF (part 1)
Application.CutCopyMode = False
wbSOF.Sheets(1).Range("Table1").SpecialCells(xlCellTypeVisible).Copy
wbBudget.Sheets("SOF DAI").Range("A2").PasteSpecial xlPasteAll
Application.CutCopyMode = False
'Filter data on 1002 Based SOF workbook (part 2)
wbSOF.Sheets(1).AutoFilterMode = False
wbSOF.Sheets(1).Select
Range("A1").AutoFilter
Range("A1").AutoFilter Field:=2, Criteria1:=Array("2015", "2016"), Operator:=xlFilterValues
Range("A1").AutoFilter Field:=3, Criteria1:=Array("=S3_*", "=Y3_*"), Operator:=xlFilterValues
'Copy, Paste, and Close the 1002 Based SOF (part 2)
wbSOF.Sheets(1).Range("Table1").SpecialCells(xlCellTypeVisible).Copy
With wbBudget.Sheets("SOF DAI")
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
wbBudget.Sheets("SOF DAI").Range("A" & LastRow + 1).PasteSpecial xlPasteAll
Application.CutCopyMode = False
wbSOF.Close SaveChanges:=False
'Activate Budget Workbook again and turn on filter
wbBudget.Activate
If Not wbBudget.Sheets("SOF DAI").AutoFilterMode Then
wbBudget.Sheets("SOF DAI").Range("A1").AutoFilter
End If
'Go to SOF Report Page and prompt user to validate data
wbBudget.Sheets("SOF Rpt").Select
wbBudget.Sheets("SOF Rpt").Range("A1").Select
wbBudget.Sheets("SOF Rpt").Range("A1").Activate
Dim Output As Integer
Output = msgbox("Please verify error checking." & vbCrLf & _
"" & vbCrLf & _
"All deltas in cells D2:I3 should equal zero." & vbCrLf & _
"" & vbCrLf & _
"If there is an error, refer to the User Manual for help.", vbOKOnly, "Validate Data")
'Clear Memory
Set wbSOF = Nothing
Set wbBudget = Nothing
End Sub
Last edited: