Aussie5380
New Member
- Joined
- Sep 30, 2022
- Messages
- 32
- Office Version
- 2019
- Platform
- Windows
Hi There,
I have run into a bit of a hiccup with a macro i have written, and was wondering if anyone could provide some advice?
I have a large spreadsheet of data given to our team each fortnight and i have written a macro to import the data off of it into another workbook (there are reasons for this) then filter a few columns based on criteria i have set as below:
However I'm having an issue with the last 2 filters i need. Column M and O has a range of "Codes" that is system wide for my job, however i want to filter both of these columns based on a table of "Codes" that I'm looking for (there's 316 of them), on another sheet in the same workbook.
The issue is due to too many variables under the Criteria Array. Is there a way around this? Can i merge a VLOOKUP into the VBA filter to find these codes on another worksheet within the same workbook and have it filter to them only?
I'm at a loss for this bit as everything else works perfect. To try something different I have added 2 columns next to the imported data set that uses a VLOOKUP to see if its listed as one of the codes I'm looking for, but as there are 2 columns, getting a third column with something along the lines of "YES"/"NO" = YES, "NO"/"YES" = YES, "NO"/"NO" = NO to play nicely is driving me bonkers.
Any assistance would be greatly appreciated, and constructive feedback is always welcome.
Shaun
I have run into a bit of a hiccup with a macro i have written, and was wondering if anyone could provide some advice?
I have a large spreadsheet of data given to our team each fortnight and i have written a macro to import the data off of it into another workbook (there are reasons for this) then filter a few columns based on criteria i have set as below:
VBA Code:
Sub Get_Data_For_TIM()
Dim FileToOpen As Variant
Dim OpenBook As Workbook
Application.ScreenUpdating = False
FileToOpen = Application.GetOpenFilename(Title:="Browse for your File and Import Range", FileFilter:="Excel Files (*.xls*),*xls*")
If FileToOpen <> False Then
Set OpenBook = Application.Workbooks.Open(FileToOpen)
OpenBook.Sheets(1).Range("A1:V99999").Copy
ThisWorkbook.Worksheets("Put TIM Report Here").Range("A1:V99999").PasteSpecial xlPasteValues
OpenBook.Close False
' Filters Team
Sheets("Put TIM Report Here").Select
Rows("1:1").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:V99999").AutoFilter Field:=2, Criteria1:="=3", _
Operator:=xlOr, Criteria2:="=9"
' Filters codes for TIM
Sheets("Put TIM Report Here").Select
ActiveSheet.Range("$A$1:V99999").AutoFilter Field:=10, Criteria1:=Array( _
"119", "139", "146", "198", "201", "202", "205", "206", "22", "236", "243", "244", "26", _
"277", "278", "279", "28", "280", "281", "310", "355", "4", "467", "48", "481", "494", "52", _
"56", "66"), Operator:=xlFilterValues
' Hides unneeded columns
Range("K:V").EntireColumn.Hidden = True
' Highlights the new amount column
Dim Lastrow As Integer
Lastrow = Sheets("Put TIM Report Here").Cells(Rows.Count, 1).End(xlUp).Row
Sheets("Put TIM Report Here").Range("Z2:Z" & Lastrow).Interior.Color = vbYellow
End If
Application.ScreenUpdating = True
End Sub
However I'm having an issue with the last 2 filters i need. Column M and O has a range of "Codes" that is system wide for my job, however i want to filter both of these columns based on a table of "Codes" that I'm looking for (there's 316 of them), on another sheet in the same workbook.
The issue is due to too many variables under the Criteria Array. Is there a way around this? Can i merge a VLOOKUP into the VBA filter to find these codes on another worksheet within the same workbook and have it filter to them only?
I'm at a loss for this bit as everything else works perfect. To try something different I have added 2 columns next to the imported data set that uses a VLOOKUP to see if its listed as one of the codes I'm looking for, but as there are 2 columns, getting a third column with something along the lines of "YES"/"NO" = YES, "NO"/"YES" = YES, "NO"/"NO" = NO to play nicely is driving me bonkers.
Any assistance would be greatly appreciated, and constructive feedback is always welcome.
Shaun