Macro to extract Data

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have tried to write code to copy data from sheet "Imported data" to sheet "Data to upload", but is not extracting the correct data


I have data from row 6 onwards in Col A:R

If Col A contains NV and Col B contains RE or Col A contains DV and M1 then I wants the data from A5 to the last row in Col R containing this criteria to be copied to sheet "Data to be uploaded"



See sample data. I have highlighted the critertia in yellow to be copied


Excel 2012
AB
5BTPlan
6NVRE
7NVAA
8DVM1
9DVM1
10DVM1
11NVB6
12DVM1
13DVM1
14NVRE
15DVM1
16DVM1
17
Inported Data


Code:
 Sub Extract_Data()

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

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

.SpecialCells(xlCellTypeVisible).Copy Worksheets("Data to be uploaded").Range("A2")
.AutoFilter
End With
End Sub


It would be appreciated if someone could assist me
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Howard,
I copied your data and code to Excel and tested it and it seemed to work fine. What doesn't seem to be working for you?
 
Upvote 0
Hi Howard,

*Edit again* Yes it does, the code works for me! :confused:

I am on Excel 2010
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,897
Messages
6,122,141
Members
449,066
Latest member
Andyg666

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