Macro: Do Not Copy rows if column A Equals 0

syndee

New Member
Joined
Jan 14, 2017
Messages
18
I need to copy only the rows that have a value not equal to zero in column A. These rows will be pasted into new workbook called Export.csv.

Is it possible. I have tried link but makes files too large. Tried pasting but have to highlight all rows and it still paste data into blank cells.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Maybe, the below is close.
You must have headers in the sheet being copied from.
It assumes that Export.csv has already been created and is open.
Make sure you change sheet names in red to match your sheet names.

and I don't know what you mean by....
and it still paste data into blank cells
as you haven't mentioned it before.


Code:
Sub Filterit()
    Dim lr As Long, lc As Long
    Application.ScreenUpdating = False

    With ThisWorkbook.Sheets("[COLOR="#FF0000"]Sheet1[/COLOR]")
        lr = .Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious, False).Row
        lc = .Cells.Find("*", , xlValues, xlPart, xlByColumns, xlPrevious, False).Column

        With .Range(.Cells(1, 1), .Cells(lr, lc))
            .AutoFilter 1, "<>0"

            On Error Resume Next
            .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Copy _
                    Workbooks("Export.csv").Sheets("[COLOR="#FF0000"]Export[/COLOR]").Range("A" & Rows.Count).End(xlUp).Offset(1)
            On Error GoTo 0
            .AutoFilter
        End With
    End With

    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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