View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Jason Lepack Jason Lepack is offline
external usenet poster
 
Posts: 120
Default How do I select nonblank data from a list?

BACKUP your spreadsheet and test this on a COPY of it.

I would create a new worksheet and manually format it to look pretty.
Then I would run this macro.

You need to change the names of the two worksheets in the code to suit.

If you have any beefs with the following code then post back.

Public Sub setupPrint()
' This Sub copies the grid that is in wsFrom to wsTo
' but only the rows that do not have zeroes.
'
' Set rF to be the Cell address of the first row after the header
' Set rT to be the first cell that you want data in the printout
'
' Asssumes that all rows have item names


Dim wb As Workbook
Dim wsFrom As Worksheet, wsTo As Worksheet
Dim rF As Range, rT As Range

Set wb = ActiveWorkbook
Set wsFrom = wb.Sheets("The name of the sheet with the grid")
Set wsTo = wb.Sheets("Your printout sheet name")

Set rF = wsFrom.Range("A2") ' first cell after the header
Set rT = wsTo.Range("A2") ' first cell with data

Do While Not rF.Offset(0, 9).Value = ""
If Not rF.Offset(0, 8) = 0 Then
wsFrom.Range(rF.Address & ":" & rF.Offset(0,
10).Address).Copy
rT.PasteSpecial xlPasteValues
Set rT = rT.Offset(1, 0)
End If
Set rF = rF.Offset(1, 0)
Loop
Set rT = Nothing
Set rF = Nothing
Set wsTo = Nothing
Set wsFrom = Nothing
Set wb = Nothing
End Sub

Jason Lepack wrote:
Cat5 Cat6 Cat7 Cat8 Total Item Name Price
0 Item1 0.1
2 2 Item2 0.11
0 Item3 0.12
2 2 Item4 0.13
3 3 Item5 0.14
0 Item6 0.15

Limited by the fact that I can only fit this many fields on the google
screen.

In this example you would want your output to look like this:
Cat5 Cat6 Cat7 Cat8 Total Item Name Price
2 2.1 Item2 0.11
2 4.11 Item4 0.13
3 3.12 Item5 0.14

Correct?

cminor wrote:
I am trying to create a list of data based on nonblank or nonzero cells in
another list. More specific: I have a group of cells, 30 Rows by 8 Columns,
which contain data (numeric) that represent quantities of 30 items from 8
categories. Each category is then totalled in the 9th column. In columns 10
and 11, I have the item name and price. Elsewhere in the worksheet, I need
to list all items that have a total quantity greater than zero along with the
item name and price. I expect this to be 6 or 8 items out of the 30.

What I am trying to avoid is listing all 30 items and having some with zero
quantities. Where the nonzero items will eventually be listed is a page to
be printed and I don't need to waste paper.