Filter data within multiple columns and copy results to new sheet

Amadan90

New Member
Joined
Jul 1, 2014
Messages
2
Hi there,

I'm rather new to VBA and I've been trying to figure out how I get my code to work properly, but after trying several things I can't seem to find an answer. I need a push in the right direction.

Below is the code I've got so far, which probably can be simplified (and needs a lot more ofcourse), and also a part of the data I need sorted out. I want to extract different kind of values to new sheets. I'll try to provide as much information as I think is relevant.

Info on the file:
  • Always 12 columns wide, rows vary around 20.000.
  • Consignment (2000+ unique values, all in format ?????-????? with occasional exceptions)
  • Transport (1000+ unique values, all in format ??????-???? + blanks)
  • Status_condt_1 (50+ unique values, only 1 or 2 letters + Z1 Z2)
  • Handl_pers (50+ unique values + blanks)
  • Description (50+ unique values, with "in conformity" as correct value

What I need:
For every different value in column A
  • if value column L is "items not scanned" copy entire row to new sheet
  • if value column L is "missing package" copy all rows of the corresponding value in column A to new sheet
Filter
  • column B for specific data + column J for data and copy all rows to new sheet

This is just a small part I want to achieve with this code. If any of you could help me out with this part I assume (or at least I hope) I can create the rest myself.

Thanks in advance!



Sub subFilter()
Dim wb1 As Workbook, sh1 As Worksheet, _
c As Range, cCon As Long, rng As Range
Set wb1 = Workbooks("podcon")
Set sh1 = wb1.Sheets(1)
Set rng = ActiveSheet.UsedRange
cCon = Cells.Find("?????-?????", ActiveCell, , xlWhole, xlByRows, _
xlNext, , , True).Row
Set c = Cells.Find("?????-?????", ActiveCell, , xlWhole, xlByRows, _
xlNext, , , True)
Range("A1").Select
Selection.AutoFilter
Range("$A$2:$A$" & cCon).AutoFilter Field:=1, Criteria1:=c
Range("L1").Select
'remove filter
Selection.AutoFilter
End Sub

CONSIGNMENTTRANSPORTSTATUSTYPESTATUS_POINTNOSTATUS_CONDT_1OBSDATEOBSTIMEREG_TIMEHANDL_PERSQUALITYDESCRIPTION
003570659323

<tbody>
</tbody>
AVEN13SX2014-07-021802180241SCANNING CANCELLED
003570659323

<tbody>
</tbody>
AVEN13Z2014-07-021802180241IN CONFORMITY
ALGRP-54592

<tbody>
</tbody>
DVEN1Z2014-07-02235965431IN CONFORMITY
ALGRP-54592

<tbody>
</tbody>
TRP591-0351

<tbody>
</tbody>
LVEN1Z2014-07-0250650742IN CONFORMITY
ARLA9-19656

<tbody>
</tbody>
DVEN2Z2014-07-021035110831IN CONFORMITY
ARLA9-19656

<tbody>
</tbody>
AVEN2Z2014-07-022334234741IN CONFORMITY
ARLA9-19656

<tbody>
</tbody>
TRP441-0340

<tbody>
</tbody>
LVEN2Z2014-07-0245552742IN CONFORMITY
ARLA9-19656

<tbody>
</tbody>
TRP441-0340

<tbody>
</tbody>
SDMSNL2Z2014-07-029211036GEERT THISSEN58IN CONFORMITY
ARLA9-19656

<tbody>
</tbody>
TRP441-0340

<tbody>
</tbody>
DMSNL2Z22014-07-0210221051GEERT THISSEN77ITEMS NOT SCANNED
BAIEU-15237

<tbody>
</tbody>
TRP481-0350

<tbody>
</tbody>
SCMSNL1Z2014-07-0211141126PIETER DRIEGEN58
IN CONFORMITY

<tbody>
</tbody>
BAIEU-15237

<tbody>
</tbody>
TRP481-0350

<tbody>
</tbody>
CMSNL1Z2014-07-0211141131PIETER DRIEGEN76
IN CONFORMITY

<tbody>
</tbody>
BAIEU-15237

<tbody>
</tbody>
TRP481-0350

<tbody>
</tbody>
AVEN1Z2014-07-021840184942
IN CONFORMITY

<tbody>
</tbody>
BAIEU-15277

<tbody>
</tbody>
TRP541-0352

<tbody>
</tbody>
SCMSNL1Z2014-07-0215171534ROB MAESSEN58
IN CONFORMITY

<tbody>
</tbody>
BAIEU-15277

<tbody>
</tbody>
TRP541-0352

<tbody>
</tbody>
CMSNL1Z22014-07-0215231534ROB MAESSEN76
ITEMS NOT SCANNED

<tbody>
</tbody>
BAIEU-15277

<tbody>
</tbody>
TRP541-0352

<tbody>
</tbody>
AVEN1Z2014-07-021741174342
IN CONFORMITY

<tbody>
</tbody>
BAIEU-15330

<tbody>
</tbody>
CVEN4Z2014-06-301700155111IN CONFORMITY
BAIEU-15330

<tbody>
</tbody>
AVEN4Z2014-07-011949194941
IN CONFORMITY

<tbody>
</tbody>
BAIEU-15330

<tbody>
</tbody>
AVEN4Z2014-06-302216221641
IN CONFORMITY

<tbody>
</tbody>
BAIEU-15330

<tbody>
</tbody>
TRP009-0337

<tbody>
</tbody>
AVEN4Z2014-06-302119211942
IN CONFORMITY

<tbody>
</tbody>
BAIEU-15342AVEN1M2014-07-0252452541MISSING PACKAGE
BAIEU-15342AVEN1M2014-07-0254154141MISSING PACKAGE
KDENL-85052NCVEN1NC2014-07-021655170511NOT COLLECTED - OUT OF HOURS
KDENL-85052SCMSNL1Z2014-07-0210281040PAUL VAN DE VEN58IN CONFORMITY
KDENL-85052CMSNL1Z2014-07-0210291050PAUL VAN DE VEN76IN CONFORMITY
KDENL-85052AVEB1Z2014-07-021911191842IN CONFORMITY

<tbody>
</tbody>
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,214,649
Messages
6,120,728
Members
448,987
Latest member
marion_davis

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