ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Defining a range by the contents of cells? (https://www.excelbanter.com/excel-programming/372011-defining-range-contents-cells.html)

travis[_3_]

Defining a range by the contents of cells?
 
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


Gary''s Student

Defining a range by the contents of cells?
 
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.
--
Gary''s Student


"travis" wrote:

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




All times are GMT +1. The time now is 05:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com