best way to copy data in a new location based on criteria?

solarissfSF

New Member
Joined
Jun 23, 2020
Messages
1
Office Version
  1. 2016
Platform
  1. Windows
hi everyone,

I have a long list of data in excel tab, what I want to do is on another tab, just show the rows that meet certain criteria, sorted by a date column. For example

master list---------------------------------
1/1/20 property taxes $500 $0
2/1/20 property taxes $500 $0
3/1/20 property taxes $0 $500

basically if the 4th column has an amount > 0, then I want that row to show up on another tab... in date order.

so in the above example only this row would show up in a different tab
3/1/20 property taxes $0 $500

What would be the best way to accomplish this? I know I can do a pivot table, but I'm not sure if that is the most efficient way. I see some posts on vlookup/match/index but again, I'm looking for the best way.

Thank You!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
The "best" way could spark debate, though the quickest way may be to AdvancedFilter copy the rows that meet the criteria (or in your case criterion, since there is only one):

VBA Code:
Sub AdvancedFilterCopy()

    Dim shtData As Worksheet
    Dim shtReport As Worksheet
    Set shtData = ThisWorkbook.Worksheets("Sheet1")
    Set shtReport = ThisWorkbook.Worksheets("Sheet2")
    shtReport.Cells.Delete

    ' Remove any filters
    If shtData.FilterMode = True Then
        shtData.ShowAllData
    End If
   
    ' Get source data
    Dim rngData As Range
    Dim rngCriteria As Range
    Set rngData = shtData.Range("A1").CurrentRegion
   
    ' The criteria range; in this case just a criterion
    Set rngCriteria = shtData.Range("F1:F2")
  
    ' Apply the filter
    rngData.AdvancedFilter Action:=xlFilterCopy _
                , CriteriaRange:=rngCriteria _
                , CopyToRange:=shtReport.Range("A1")

End Sub
Sheet1:
best-way-to-copy-data-in-a-new-location-based-on-criteria.1138060.xlsm
ABCDEF
1DateText1$2$2$
21/01/2020pt$500$0>0
32/01/2020pt$500$0
43/01/2020pt$0$500
Sheet1


Note I've put the criterion in cells F1:F2 of the "data" sheet (Sheet1), though it could be elsewhere. The "report" is Sheet2, the content of which is deleted each time.

This will be super fast. I tried it on >8,000 rows of data and it's instantaneous.

Output (when using your original data only):
1594020235704.png
 
Upvote 0

Forum statistics

Threads
1,214,956
Messages
6,122,465
Members
449,085
Latest member
ExcelError

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