Copying only filtered data to another cell

afc171

Board Regular
Joined
Jan 14, 2017
Messages
143
Office Version
  1. 2013
Platform
  1. Windows
Hi all,

I am trying to filter the last column F12 (with Y) and copying the showing data with Y and pasting into cells A3 to E10 (only allowing 8 rows)

In the example it shows rows 16, 20, 36 and 45 to be copied, but next time this might be different depending on the stock checked in column F12.

How can I copy the data only filtered from whatever is visible?

Thank you
 

Attachments

  • Screenshot 2021-05-02 at 17.52.41.png
    Screenshot 2021-05-02 at 17.52.41.png
    39.8 KB · Views: 10

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
If you are ok with copying values only, how about this...

VBA Code:
Sub CopyFilterRng()

    Dim rng

    rng = ActiveSheet.AutoFilter.Range.Offset(1, 0)
    Range("A3").Resize(8, 5) = rng
        
End Sub
 
Upvote 0
Thanks @igold

That seems to copy the data from the top of list, not the filtered cells... ?
 

Attachments

  • Screenshot 2021-05-02 at 20.23.01.png
    Screenshot 2021-05-02 at 20.23.01.png
    92.7 KB · Views: 6
Upvote 0
Worked for me with a test mock up. Did you clear the contents on top before you ran the code...

It does not appear that the bottom half has filter applied to it on this second picture that you supplied...
 
Last edited:
Upvote 0
I just posted that screenshot to show what copied to sell A3..

Yes cleared the contents, apply filter in cell F12 then run the VBA and get what is in the attached image.

So its copying the top 8 rows from B13 not the filtered "y" rows
 

Attachments

  • Screenshot 2021-05-02 at 22.29.52.png
    Screenshot 2021-05-02 at 22.29.52.png
    55.4 KB · Views: 8
Upvote 0
My bad. Yes, this code is not working as intended.
 
Upvote 0
Sorry about my previous faux pas. How about this. You should know that this code will create and delete a temporary "helper" sheet, but it does fill your requirements...

VBA Code:
Sub CopyFilterRng()

    Dim ws As Worksheet: Set ws = ActiveSheet
    Dim rng As Range
    Dim arr
    
    Application.ScreenUpdating = False
    Set rng = ws.AutoFilter.Range.Offset(1, 0)
    rng.Copy
    Worksheets.Add.Name = "tmp"
    Range("A1").PasteSpecial Paste:=xlPasteValues
    arr = Worksheets("tmp").Range("A1:F8")
    Application.DisplayAlerts = False
    Worksheets("tmp").Delete
    Application.DisplayAlerts = True
    ws.Range("A3").Resize(8, 6) = arr
    Application.ScreenUpdating = True
            
End Sub

I hope this helps...
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,181
Members
449,071
Latest member
cdnMech

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