ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Defining a range in vba???? Please help (https://www.excelbanter.com/excel-programming/385615-defining-range-vba-please-help.html)

Need Help Fast![_2_]

Defining a range in vba???? Please help
 
I have multiple ranges in a spreadsheet. The problem is I want to define
them, and use them in a function in vba. I do not want the cells that are
zero or smaller to be included in the range when the range is being used in
the function. I was wondering if it is possible to say like if range(A1:B200)
0 then range(A1:B200) = rngtemp. Can someone help? Thanks


Gary''s Student

Defining a range in vba???? Please help
 
Sub range_reducer()
Dim r1 As range, r2 As range
Set r1 = range("A1:B200")
Set r2 = Nothing
For Each r In r1
If r.Value 0 Then
If r2 Is Nothing Then
Set r2 = r
Else
Set r2 = Union(r, r2)
End If
End If
Next

MsgBox (r2.Address)
End Sub

Starting with r1, we build r2 to contain only the positives.
--
Gary''s Student
gsnu200711


Need Help Fast![_2_]

Defining a range in vba???? Please help
 
Sweet. Thank you very much.

"Gary''s Student" wrote:

Sub range_reducer()
Dim r1 As range, r2 As range
Set r1 = range("A1:B200")
Set r2 = Nothing
For Each r In r1
If r.Value 0 Then
If r2 Is Nothing Then
Set r2 = r
Else
Set r2 = Union(r, r2)
End If
End If
Next

MsgBox (r2.Address)
End Sub

Starting with r1, we build r2 to contain only the positives.
--
Gary''s Student
gsnu200711



All times are GMT +1. The time now is 07:34 PM.

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