#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 86
Default Create 3 Ranges in 1

Hello Experts!

I have a single range B2:B50. Within this range are three contiguous ranges
that are ever-shrinking or expanding depending on user input. At one point,
the ranges might go B2:B10, B11:B40, B41:B50, but at the very next point, the
ranges might change to B2:B17, B18:B34, B35:B50. I never know.

The visible change is this: the target range will have data figures and the
other two will turn to Zeroes. I need a dynamic range formula that finds
just the non-zeroed range in the column.

Please help. You always have in the past.

Thank you for your time.

Arlen
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Create 3 Ranges in 1

Sub findvals()
Set r = Range("B2:B50")
Set r1 = Nothing
For Each r2 In r
If r2.Value < 0 Then
If r1 Is Nothing Then
Set r1 = r2
Else
Set r1 = Union(r1, r2)
End If
End If
Next
MsgBox (r1.Address)
End Sub

--
Gary''s Student - gsnu200799
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 86
Default Create 3 Ranges in 1

Gary's Student,

How can I do this as a dynamic named range instead?

Thanks for your help so far.

Arlen

"Gary''s Student" wrote:

Sub findvals()
Set r = Range("B2:B50")
Set r1 = Nothing
For Each r2 In r
If r2.Value < 0 Then
If r1 Is Nothing Then
Set r1 = r2
Else
Set r1 = Union(r1, r2)
End If
End If
Next
MsgBox (r1.Address)
End Sub

--
Gary''s Student - gsnu200799

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,058
Default Create 3 Ranges in 1

Let's assume that we have already defined a Named Range called "stuff"
Let's build on the macro:

Sub findvals()
Set r = Range("B2:B50")
Set r1 = Nothing
For Each r2 In r
If r2.Value < 0 Then
If r1 Is Nothing Then
Set r1 = r2
Else
Set r1 = Union(r1, r2)
End If
End If
Next
s = r1.Address(ReferenceStyle:=xlR1C1)
ActiveWorkbook.Names("stuff").Delete
ActiveWorkbook.Names.Add Name:="stuff", RefersToR1C1:="=Sheet1!" & s
MsgBox (s)
End Sub

So once r1 as been constructed, we first delete the old Name "stuff" and
then re-create it based upon the new r1.
--
Gary''s Student - gsnu200799


"Arlen" wrote:

Gary's Student,

How can I do this as a dynamic named range instead?

Thanks for your help so far.

Arlen

"Gary''s Student" wrote:

Sub findvals()
Set r = Range("B2:B50")
Set r1 = Nothing
For Each r2 In r
If r2.Value < 0 Then
If r1 Is Nothing Then
Set r1 = r2
Else
Set r1 = Union(r1, r2)
End If
End If
Next
MsgBox (r1.Address)
End Sub

--
Gary''s Student - gsnu200799

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 86
Default Create 3 Ranges in 1

I think I understand what the code is doing, but I don't know why it's having
a problem with the Set r = Range (2nd Line).

Gary's Student, if I do this as a macro, does it have to be run manually?
Because users are going to be switching data alot, so that would be an extra
step. I tried to create a dynamic named range called "Labels" using the name
box that looks like

=OFFSET(Data!$A$2,COUNTIF(Data!$A$2:$A$43,"=0"),0, COUNTIF(Data!$A$2:$A$43,"0"))

but it's no good. Any more thoughts?



"Gary''s Student" wrote:

Let's assume that we have already defined a Named Range called "stuff"
Let's build on the macro:

Sub findvals()
Set r = Range("B2:B50")
Set r1 = Nothing
For Each r2 In r
If r2.Value < 0 Then
If r1 Is Nothing Then
Set r1 = r2
Else
Set r1 = Union(r1, r2)
End If
End If
Next
s = r1.Address(ReferenceStyle:=xlR1C1)
ActiveWorkbook.Names("stuff").Delete
ActiveWorkbook.Names.Add Name:="stuff", RefersToR1C1:="=Sheet1!" & s
MsgBox (s)
End Sub

So once r1 as been constructed, we first delete the old Name "stuff" and
then re-create it based upon the new r1.
--
Gary''s Student - gsnu200799


"Arlen" wrote:

Gary's Student,

How can I do this as a dynamic named range instead?

Thanks for your help so far.

Arlen

"Gary''s Student" wrote:

Sub findvals()
Set r = Range("B2:B50")
Set r1 = Nothing
For Each r2 In r
If r2.Value < 0 Then
If r1 Is Nothing Then
Set r1 = r2
Else
Set r1 = Union(r1, r2)
End If
End If
Next
MsgBox (r1.Address)
End Sub

--
Gary''s Student - gsnu200799

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
How do I automatically create ranges? ExcelHelpPlease Excel Discussion (Misc queries) 11 July 27th 07 07:31 AM
Create new list with defined ranges BKO Excel Worksheet Functions 0 June 13th 07 11:35 AM
Create new list with defined ranges BKO Excel Worksheet Functions 0 June 13th 07 11:30 AM
Create list of Named Ranges Jim Tibbetts Excel Worksheet Functions 4 February 15th 07 05:29 PM
Adding data to create ranges jodieg Excel Worksheet Functions 4 February 13th 07 09:34 PM


All times are GMT +1. The time now is 05:09 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"