VBA copy and paste filter problems

twl2009

Board Regular
Joined
Jan 7, 2016
Messages
247
Hi

The below code copy and pastes info from sheet "Csv" and saves it onto a mac desktop as a csv file. The sheet "csv" has a filtered area, if I use the filter to select some rows the code only copy and pastes and saves those rows, but when I 'select all' from the filter box the macro below fails to copy and paste and save all the rows, instead it does whatever the previous filtered result was.

Is there an obvious reason for this, been googling for ages

Thanks

Code:
<style type="text/css">p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=000000]#000000[/URL] ; background-color: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ffffff]#ffffff[/URL] }p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; background-color: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ffffff]#ffffff[/URL] ; min-height: 13.0px}p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=000000]#000000[/URL] ; background-color: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ffffff]#ffffff[/URL] ; min-height: 13.0px}p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=011993]#011993[/URL] ; background-color: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=ffffff]#ffffff[/URL] }span.s1 {color: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=011993]#011993[/URL] }span.s2 {color: [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=000000]#000000[/URL] }</style>Sub ExportMac()




    Application.DisplayAlerts = False


    Application.ScreenUpdating = False


    Application.CutCopyMode = False


    Dim wsCopy As Worksheet, wsPaste As Worksheet
    Dim wb As Workbook
    Dim sFileName As String, sPath As String, sName As String
    
    sPath = "/Users/User/Desktop/"
    sFileName = "ProductFile" & ".csv"
    Set wsCopy = ThisWorkbook.ActiveSheet
    Set wb = Workbooks.Add
    Set wsPaste = wb.Sheets(1)


    wsCopy.Cells.Copy
    wsPaste.Cells.PasteSpecial Paste:=xlValues
    Application.CutCopyMode = False
    
    wsPaste.Rows(3).Delete
    wsPaste.Rows(2).Delete
    wsPaste.Rows(1).Delete
    wsPaste.Columns(1).Delete


    wb.SaveAs Filename:=sPath & sFileName, FileFormat:=xlCSV


    ActiveWorkbook.Close


    Application.DisplayAlerts = True


    Application.ScreenUpdating = True


    ActiveSheet.Range("B4").Select


End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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