copy data greater than 0

ymdeek

New Member
Joined
Mar 19, 2018
Messages
1
hello

I am new to macro and I need your help to create a macro that copy only the data with value > 0 to a new workbook. As you can see from the table, some data have no value so I am trying to avoid copying them by using if condition. Any one can help?

see image here
ettTnx

https://ibb.co/ettTnx

Note: ignore the zeros in Country
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
in my example the macro runs down Col A (no nulls) until the end (null cell)
it checks the value of kMyCOL (col 4, but offset from 1) for the zero, if not zero , then it copies.
alter these for your workbook. change Const kMyCOL = 3


Code:
Public Sub CopyNonZeros()
Dim wbSrc As Workbook, wbTarg As Workbook
Const kMyCOL = 3


    'copy headers
Set wbSrc = ActiveWorkbook
Rows("1:1").Select
Selection.Copy
Workbooks.Add
Set wbTarg = ActiveWorkbook
ActiveSheet.Paste
Range("A2").Select


wbSrc.Activate
Range("A2").Select
While ActiveCell.Value <> ""
   Select Case ActiveCell.Offset(0, kMyCOL).Value
      Case ""
        GoSub CopyRow
      Case 0
      Case Else
        GoSub CopyRow
   End Select
   
   NextRow
Wend


Set wbSrc = Nothing
Set wbTarg = Nothing
Exit Sub


CopyRow:
'----------
Rows(ActiveCell.Row & ":" & ActiveCell.Row).Select
Selection.Copy
wbTarg.Activate
ActiveSheet.Paste
NextRow
wbSrc.Activate
Return
End Sub


Private Sub NextRow()
ActiveCell.Offset(1, 0).Select
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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