Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42316

MsOf10 Autofilter - how to have it look to see if field contains

$
0
0
Good afternoon,

I have been going crazy for the past two days trying to get my code to work, so I think it is about time I see if someone can help me.

The three red lines below are where I am at a loss. Here is what I am trying to do. I need to have it look at the a Worksheet called Territory and based on what is in a particular cell, I need it to then filter the selected sheet. For example the first one needs to filter the worksheet titled Records (field 7). The catch is that I need to to filter based on Contains not on Equals. Is it possible to do this? I have tried everything, but without a lot of manual intervention to make the fields match, I can't get it to work.

Any help would be appriciated!!!

- Heather


Sub GetData()

Dim AN As String
Dim Tabname As String
Dim ReportName As String
Dim myrange As String
Dim colrange As Integer
Dim PlanReportName As String



Dim xlCalc As XlCalculation

xlCalc = Application.Calculation
Application.Calculation = xlCalculationManual
On Error GoTo CalcBack

Windows("TechData.xlsm").Activate

Sheets("Territory").Select

Tabname = Range("g6").Value
ReportName = Range("h6").Value
PlanReportName = Range("i6").Value

AN = Range("g3")

Windows(Filename).Activate

Sheets("LocationData").Select
ActiveSheet.Unprotect

Range("a1:k5000").Select
Selection.ClearContents

Sheets("Cert Progress - Construction").Select
ActiveSheet.Unprotect
Range("g1:am500").Select
Selection.ClearContents

Sheets("Cert Progress - Forestry").Select
ActiveSheet.Unprotect
Range("g1:am500").Select
Selection.ClearContents

Sheets("Certification Summary").Select
ActiveSheet.Unprotect

Windows("TechData.xlsm").Activate

Sheets("Records").Select
Selection.AutoFilter Field:=7, Criteria1:=AN, Operator:=xlAnd
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy

Windows(Filename).Activate

Sheets("LocationData").Select
Range("A1").Select
ActiveSheet.Paste

Columns("e:e").Select
Application.CutCopyMode = False
Range("e1:e10000").AdvancedFilter Action:=xlFilterCopy, CopyToRange:= _
Columns("m:m"), Unique:=True

Range("r1:z5000").Select
Selection.ClearContents

Windows("TechData.xlsm").Activate

Sheets("Credential Data").Select
Selection.AutoFilter Field:=7, Criteria1:=AN, Operator:=xlAnd
Range("a1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy

Windows(Filename).Activate

Sheets("LocationData").Select
Range("R1").Select
ActiveSheet.Paste

Application.CutCopyMode = False


Range("ab1:ad5000").Select
Selection.ClearContents

Windows("TechData.xlsm").Activate

Sheets("Certificate Data").Select
Selection.AutoFilter Field:=6, Criteria1:=AN, Operator:=xlAnd
Range("g1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy

Windows(Filename).Activate

Sheets("LocationData").Select
Range("ab1").Select
ActiveSheet.Paste

Application.CutCopyMode = False

Viewing all articles
Browse latest Browse all 42316

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>