Defining a range by the contents of cells?

  • Thread starter Thread starter travis
  • Start date Start date
T

travis

I have many rows of data and I would like to put some of that data into
a range (so I can chart that range) conditional on the contents of the
cells.

If the cells are a bunch of zeros, I do NOT want them to be included in
the range.

However if they have non-zero values in there, even if it is just one
or two non-zero values in a row with mostly zeros, I'd like them to be
in the range.

Can anyone help?

Travis
 
You can make a range with the UNION() function:

Sub gsnu()
Dim r As Range
Dim rNotEmpty As Range

For Each r In Selection
z = r.Value
If z = 0 Then
Else
If rNotEmpty Is Nothing Then
Set rNotEmpty = r
Else
Set rNotEmpty = Union(rNotEmpty, r)
End If
End If
Next

MsgBox (rNotEmpty.Address)
End Sub



Delete the msgbox once you are satisfied.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top