Copy AutoFiltered result to another worksheet

ExcelHound

New Member
Joined
Jun 4, 2011
Messages
9
I’m looking for assistant with the following macro – this works well but I would like to achieve some small tweaks.<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
I’m looking for a macro to select to contents of Column ‘A’ on Sheet1 where Sheet1 has an autofilter – Column D is AutoFiltered to only select entries with a ‘Yes’ value. <o:p></o:p>
Sheet1 has a Header starting at row A5. Sheet1 has multiple columns of data included in the AutoFilter but I only want to select the filtered result of column A (minus the header) then paste it onto Sheet2 at A5 (the next free cell).
<o:p></o:p>
Is this possible? Many thanks in advance.<o:p></o:p>
<o:p> </o:p>
The macro works fine but copies all columns, I just want to copy column A.<o:p></o:p>
Sub CopyFilter()<o:p></o:p>
Dim rng As Range<o:p></o:p>
Dim rng2 As Range<o:p></o:p>
<o:p> </o:p>
With ActiveSheet.AutoFilter.Range<o:p></o:p>
On Error Resume Next<o:p></o:p>
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _<o:p></o:p>
.SpecialCells(xlCellTypeVisible)<o:p></o:p>
On Error GoTo 0<o:p></o:p>
<o:p> </o:p>
End With<o:p></o:p>
<o:p> </o:p>
If rng2 Is Nothing Then<o:p></o:p>
MsgBox "No data to copy"<o:p></o:p>
<o:p> </o:p>
Else<o:p></o:p>
Worksheets("Sheet2").Cells.Clear<o:p></o:p>
Set rng = ActiveSheet.AutoFilter.Range<o:p></o:p>
rng.Offset(1, 0).Resize(rng.Rows.Count - 1).Copy _<o:p></o:p>
Destination:=Worksheets("Sheet2").Range("A1")<o:p></o:p>
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
hi,

i notice you got the code from the contextures website. have you tried using the macro recorder? it will give you the basics of what you want. after recording it, change the specified ranges to make them dynamic and off you go. let me know if i can try and help further. ajm
 
Upvote 0
Many thanks for the reply; I did try using the recorder but I cant seem to get it to be dynamic with the select - it just selects the cell range where the values are.

That maco enclosed in the original post works a charm but selects all columns of data then pastes into onto sheet2, is it a qucik fix to have it only copy columnA entries.

I also wanted to try and combine it with the following to dynamically paste the results at the end of the existing entries in column A.

Cells(Rows.Count, "A").End(xlUp).Offset(1).Select


many thanks
 
Upvote 0
weird that autofilter range bit. i believe that by using that in the code it makes your selection become the entire autofilter range, irrespective of which column you specify. i have a messy macro that should do the trick, given what we have discussed so far.

Code:
Sub Macro1()
 Sheets("Sheet1").Activate
   Range("A6").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.SpecialCells(xlCellTypeVisible).Copy
    Sheets("Sheet2").Select
    lastrow = Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Row
    Range("A" & lastrow + 1).Select
    ActiveSheet.Paste
End Sub

assumptions: the autofiltered range will always be on "Sheet1" (if not change wherever you see "Sheet1" to your sheet name)

also, i assumed that you already had something in column A on Sheet 2, given the way you referred to the next free cell.

hope this can be of some help. I am still a hack when it comes to code but get a kick out of using it, all the same.
 
Upvote 0
mate, no problems. helping others on this board is the best way to repay the time and kindness of those that have helped me in the past. have a great week. ajm
 
Upvote 0

Forum statistics

Threads
1,224,524
Messages
6,179,308
Members
452,904
Latest member
CodeMasterX

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