PC Review


Reply
Thread Tools Rate Thread

Defining a range in vba???? Please help

 
 
=?Utf-8?B?TmVlZCBIZWxwIEZhc3Qh?=
Guest
Posts: n/a
 
      19th Mar 2007
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?R2FyeScncyBTdHVkZW50?=
Guest
Posts: n/a
 
      19th Mar 2007
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

 
Reply With Quote
 
=?Utf-8?B?TmVlZCBIZWxwIEZhc3Qh?=
Guest
Posts: n/a
 
      19th Mar 2007
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
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Defining a range as a subset of cells in another range Jay Microsoft Excel Programming 12 23rd Dec 2009 06:38 PM
defining a range dhgerstman@gmail.com Microsoft Excel Programming 2 18th Mar 2008 03:14 PM
Defining series range for named range =?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?= Microsoft Excel Programming 1 3rd Aug 2006 09:00 PM
Defining a Range =?Utf-8?B?S2F2YWw=?= Microsoft Excel Programming 2 5th Sep 2004 11:53 PM
Defining a Range Ric Microsoft Excel Programming 4 26th Apr 2004 07:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:04 PM.