Copy row only if one cell's value is not 0 [Solved]

Ask a question victhor1977 1Posts Thursday April 14, 2016Registration date April 14, 2016 Last seen - Latest answer on Apr 18, 2016 03:13AM
I would like to copy from a sheet to another only the rows in wich a cell ex.A1 has a value different from zero or blank.
Thanks a lot!
See more 
moins plus
Hello Victhor1977,

The following code may do the task for you:-

Sub CopyStuff()

Application.ScreenUpdating = False
Application.DisplayAlerts = False

     Range("A1:A" & Cells(Rows.Count, 1).End(xlUp).Row).AutoFilter 1, "<>" & "", xlAnd, "<>" & 0#
     Range("A2:I" & Cells(Rows.Count, 9).End(xlUp).Row).Copy Sheet2.Range("A" & Rows.Count).End(3)(2)
     Range("A2:I" & Cells(Rows.Count, 9).End(xlUp).Row).Delete
Application.DisplayAlerts = True
Application.ScreenUpdating = True

End Sub

Any rows of data that do not have a blank cell in Column A or a zero value in Column A will be transferred to sheet2 using the above code. The code will also delete the same rows from sheet1 once they have been transferred to sheet2.

Following is the link to my test work book for you to peruse:-

Click on the Transfer button to see the code at work. My test work book has nine columns (A - I). Change the references in the code to suit your actual work book including the column number (shown as 9 in the above code: I=9, J=10 etc.).

Test the code in a copy of your work book first.

I hope that this helps.

Victhor1977- Apr 18, 2016 02:24AM
Worked like a charm!
Add comment
moins plus
Hello Victhor,

Excellent! I'm glad that I was able to help.

Add comment

Members get more answers than anonymous users.

Being a member gives you detailed monitoring of your requests.

Being a member gives you additional options.

Not a member yet?

sign-up, it takes less than a minute and it's free!