Apply Filter and cut and paste to new spreadsheet

JoeRooney

Board Regular
Joined
Nov 27, 2017
Messages
169
Office Version
  1. 365
Hi,

Wondering if someone could help me with some code I need to apply a filter , cut the visible rows and paste into a new sheet.

I then want to return to the original sheet and delete the blank rows.

When I record it records the exact ranges , If someone could advise me how to do it without naming specific ranges that would be great.

I need to filter column P , for “00GHT” , my current code is below.

Any help is greatly appreciated

VBA Code:
  Rows("3:3").Select
    Selection.AutoFilter
    ActiveWindow.SmallScroll ToRight:=4
    ActiveSheet.Range("$A$3:$AEN$5386").AutoFilter Field:=16, Criteria1:= _
        "00GHT"
    Rows("1:1").Select
    Range("E1").Activate
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.copy
    Sheets("Sheet1").Select
    Range("A1").Select
    ActiveSheet.Paste
    Rows("21:21").Select
    Range("E21").Activate
    Range(Selection, Selection.End(xlDown)).Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlUp
    Selection.AutoFilter
    Range("E4").Select
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
How about
VBA Code:
With ActiveSheet
    If .AutoFilterMode Then .AutoFilterMode = False
    .Range("A3:AEN3").AutoFilter 16, "00GHT"
    .AutoFilter.Range.Offset(1).Copy Sheets("Sheet1").Range("A1")
    .AutoFilter.Range.Offset(1).Delete
    .AutoFilterMode = False
End With
 
Upvote 0
Thank you, works perfectly , just had to make a few small adjustments final code below:

VBA Code:
Sub Filter()

    Sheets("POL").Select
    With ActiveSheet
    If .AutoFilterMode Then .AutoFilterMode = False
    .Range("A3:AEN3").AutoFilter 16, "00GHT"
    .AutoFilter.Range.Offset(1).copy Sheets("Sheet1").Range("A1")
    .AutoFilter.Range.Offset(-2).copy
    Sheets("Sheet1").Select
    Range("A1").Select
    ActiveSheet.Paste
    Sheets("POL").Select
    .AutoFilterMode = False
End With

With ActiveSheet
    If .AutoFilterMode Then .AutoFilterMode = False
    .Range("A3:AEN3").AutoFilter 16, "00GHT"
    .AutoFilter.Range.Offset(1).Delete
    .AutoFilterMode = False
    
    End With

End Sub
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,799
Members
449,095
Latest member
m_smith_solihull

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