macro to extract certain Criteria

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,589
Office Version
  1. 2021
Platform
  1. Windows
I have data in Col A and B on sheet "Imported Data"


I only want to extract the following Types to be extracted


Currently only DV Col A and M1 Col B is being extracted

I also need NV and RE to be extracted


It would be appreciated if someone could assist me




Col A Col B
DV M1
NV RE



Book1
AB
4BTPlan
5NVB6
6NVE6
7NVE6
8NVB6
9NVB6
10NVB6
11NVB6
12NVB6
13NVB6
14NVC6
15NVC6
16NVE6
17NVC6
18NVB6
19NVE6
20NVRE
21NVB6
22DVM1
23DVM1
24DVM1
25DVM1
26DVM1
Sheet1




Code:
 Sub Extract_Criteria()

Sheets("Imported Data").Select
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row

With ActiveSheet.Range("A5:J" & Lastrow)
.AutoFilter Field:=1, Criteria1:=Array("DV", "NV"), Operator:=xlFilterValues
.AutoFilter Field:=2, Criteria1:=Array("M1", "RE"), Operator:=xlFilterValues

.SpecialCells(xlCellTypeVisible).Copy Worksheets("Extracted DVM1_NVRE").Range("A2")
.AutoFilter
End With


End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
try this:

Code:
Option Explicit


Sub FindX()
    Dim s1 As Worksheet, s2 As Worksheet
    Set s1 = Sheets("Sheet1")
    Set s2 = Sheets("Sheet2")
    Dim lr As Long, i As Long
    lr = s1.Range("A" & Rows.Count).End(xlUp).Row
    Application.ScreenUpdating = False
    For i = 2 To lr
        lr2 = s2.Range("A" & Rows.Count).End(xlUp).Row
        If s1.Range("A" & i) = "DV" Then
            If s1.Range("B" & i) = "M1" Then
                s1.Range("A" & i & ":B" & i).Copy s2.Range("A" & lr2 + 1)
            ElseIf s1.Range("A" & i) = "NV" Then
                If s1.Range("B" & i) = "RE" Then
                    s1.Range("A" & i).Copy s2.Range("A" & lr2 + 1)
                End If
            End If
        End If
    Next i
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
    MsgBox "completed"
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,874
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top