Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 25
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Defining series range for named range Barb Reinhardt Excel Programming 1 August 3rd 06 09:00 PM
defining a range Stefi Excel Programming 2 July 20th 06 09:18 AM
Defining a range for a look up MH UK Excel Programming 5 February 16th 06 03:11 PM
Defining a Range Ric[_5_] Excel Programming 4 April 26th 04 07:34 PM
Defining a range Matt Excel Programming 3 January 23rd 04 03:21 PM


All times are GMT +1. The time now is 04:25 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"