VBA code to filter data

STEVENS3010

Board Regular
Joined
Feb 4, 2020
Messages
87
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi all,

I have a sheet with 5 columns of data that I need filter one column for a a specific value. I've used the macro recorded to help me; the script is below...

VBA Code:
Selection.AutoFilter
    ActiveSheet.Range("$A$2:$E$5654").AutoFilter Field:=3, Criteria1:=Array( _
        "AWAIT DIP UNDERWRITING"), _
        Operator:=xlFilterValues

My questions are, based on the above script, am I correct in assuming it will only filter the range between A2:E5654? If so, as the number of rows of data will be changing, is it possible to code the script to run between columns A and E, but to automatically look for the last row, rather than specifying a particular row number?

My second question then was around copying and pasting the filtered data to a new sheet. Is it possible? If so, is it clever enough to only copy and paste the filtered data, even if this changes every time the filter is applied?

If anybody could help I'd really appreciate it.

Thanks.
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I’ve managed to sort it now, thanks though.

I’ve just added a line of code to hide the columns I don’t need before I apply the code you helped me with.
 
Upvote 0
Glad you sorted it & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,078
Latest member
skydd

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