How to looping through data and copy to new sheet if condition is met in VBA

XcelNoobster

New Member
Joined
Jun 7, 2022
Messages
40
So I have an excel sheet called Data that has up to Column I. My data start on row 4. I want to loop through all n rows and copy all the data, but don't copy the row where Column G is empty AND Column H is 0. How would the macro look like? I know the logic, but the syntax is very confusing for me.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Welcome to the Board!

How about just using an Advanced Filter to filter the records you want and copy to a new location?
Here is a link that shows you how to do that: How to copy data to another worksheet with Advanced Filter in Excel?

If you really want VBA, here is a link that shows you how you can filter and copy just the visible rows via VBA code:
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,179
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