Excel in Practice

A common spreadsheet problem that relates to macros and VBA is having to loop through a variable number of rows of data and do something to rows that meet certain criteria. For instance, the worksheet in Figure 30.20 (Sales.xls) contains sales data for more than 400 products. Notice that some of the products in the current year have zero sales values. These are discontinued products.

Suppose that you're going to export this data to another program and you only want to export viable products, not discontinued ones. You could work your way through the list and manually delete the rows that contain discontinued products. With more than 400 products, though, this could take quite some time! So as an alternative, you can use VBA to remove the unwanted rows. Here's how: