Pasting a filtered table with a Macro

noerom

New Member
Joined
Oct 21, 2013
Messages
2
I need some help with a macro. I created an event where a cell is changed and thus updates the table by filtering with the number that gets updated- this part works fine. The problem I'm having is that the macro I created is supposed to copy the filtered information and paste it into a new Workbook and worksheet and instead, it copies the correct number of rows of the table filtered, but starting in row one. To exemplify: the table is filtered in row 1 and the data shows in 3 rows (Numbers 3, 9, 210), instead of copying those three rows, it copies (or pastes) row 1,2,3,and 4. So, I need to know if there´s anyway to only copy and the filtered data. Any help will be greatly appreciated!

Here´s what the piece of code looks like:

Sheets("Variación en Detalle").Select
Range("A1:L1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Application.CutCopyMode = False
Selection.Copy
Windows("Book1").Activate
Sheets("Sheet3").Select
Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
, SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Try this code instead:

Code:
Sub Test()

    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    
    Set ws1 = ActiveWorkbook.Worksheets("Variación en Detalle")
    Set ws2 = Workbooks.Add.Worksheets(1)
    
    ws1.Range("A1").CurrentRegion.Copy
    ws2.Range("A1").PasteSpecial xlPasteAllUsingSourceTheme

End Sub
 
Upvote 0
It's still doing the same thing... just copies the same number of rows as the selection, but starting from row number 1 down.
 
Upvote 0

Forum statistics

Threads
1,213,546
Messages
6,114,256
Members
448,557
Latest member
richa mishra

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