Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problem collecting Range Values


I am trying to collect and Range, that is made up of a number o
"sub-ranges" if you like.

I create three ranges the normal way by giving cell references. Thi
works fine and my three ranges hold the values that I need in th
Value2 attribute.

The ranges aren't next to each other and I want to join them into on
range, so I've used the Union() method. This combines the ranges an
if I now use the select method this highlights my range and you can se
that it is the range I'm after.

However the value2 attribute of this combined range, doesn't hold al
the values covered by the range? In fact it only contains values fro
the first range I pass into Union()

Any ideas? Or other solutions to collecting non-contigous ranges

--
richcoleu
-----------------------------------------------------------------------
richcoleuk's Profile: http://www.excelforum.com/member.php...fo&userid=3310
View this thread: http://www.excelforum.com/showthread.php?threadid=52912

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 336
Default Problem collecting Range Values

You're right - the locals window only shows Value2 for the first range - weird!

However, if you use Value you can pick up all the cells in the range, eg:

Dim myRange As Range
Dim myCell As Range
Set myRange = Application.Union(Range("A1:A3"), Range("A5:A6"),
Range("A8:A10"))
For Each myCell In myRange
MsgBox myCell.Value
Next


"richcoleuk" wrote:


I am trying to collect and Range, that is made up of a number of
"sub-ranges" if you like.

I create three ranges the normal way by giving cell references. This
works fine and my three ranges hold the values that I need in the
Value2 attribute.

The ranges aren't next to each other and I want to join them into one
range, so I've used the Union() method. This combines the ranges and
if I now use the select method this highlights my range and you can see
that it is the range I'm after.

However the value2 attribute of this combined range, doesn't hold all
the values covered by the range? In fact it only contains values from
the first range I pass into Union()

Any ideas? Or other solutions to collecting non-contigous ranges?


--
richcoleuk
------------------------------------------------------------------------
richcoleuk's Profile: http://www.excelforum.com/member.php...o&userid=33103
View this thread: http://www.excelforum.com/showthread...hreadid=529123


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problem collecting Range Values


Okay thanks for that,

How ever I am using some C# behind excel and I need to be able to pas
in a range that has a value2 attribute that holds all the data from th
multiple ranges.

How can I make sure this 1 range has all the data stored in Value2

--
richcoleu
-----------------------------------------------------------------------
richcoleuk's Profile: http://www.excelforum.com/member.php...fo&userid=3310
View this thread: http://www.excelforum.com/showthread.php?threadid=52912

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Problem collecting Range Values

Hi
You could output an array of variants.
Each range object has an Areas property to count the disconnected bits
of the range. for your three areas you could try

Function Tester() as Variant
Dim OutputValues() as Variant
AreaCount = Selection.Areas.Count
ReDim OutputValues(1 to AreaCount)
for i = 1 to AreaCount
OutputValues(i) =Selection.Areas(i).Value
next i
Tester = OutputValues
end function

Then OutPutValues(2) would be the array of values in area 2 of the
selection.

regards
Paul

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problem collecting Range Values


Okay I think I'm nearly there. The only trouble I have now is that th
C# method I need to use expects a Range[] and i don't think it like
being passed a Variant, in the example you gave Teste

--
richcoleu
-----------------------------------------------------------------------
richcoleuk's Profile: http://www.excelforum.com/member.php...fo&userid=3310
View this thread: http://www.excelforum.com/showthread.php?threadid=52912



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Problem collecting Range Values


No one have anyideas how i can convert to a Range[]


--
richcoleuk
------------------------------------------------------------------------
richcoleuk's Profile: http://www.excelforum.com/member.php...o&userid=33103
View this thread: http://www.excelforum.com/showthread...hreadid=529123

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Problem collecting Range Values

Hi
I sent you solution privately, but just for this thread:

An array of Ranges output:

Function Tester2() As Variant
Dim OutputRanges() As Range, i As Integer
AreaCount = Selection.Areas.Count
ReDim OutputRanges(1 To AreaCount)
For i = 1 To AreaCount
Set OutputRanges(i) = Selection.Areas(i)
Next i
Tester2 = OutputRanges
End Function

Public Sub test()
Dim myValues As Variant
For i = 1 To UBound(Tester2)
Set Testarea = Tester2(i)
MsgBox Testarea.Address
Next i
End Sub

A Collection of Ranges output:

Function Tester2() As Collection
Dim OutputRanges As New Collection, i As Integer
AreaCount = Selection.Areas.Count
For i = 1 To AreaCount
OutputRanges.Add Selection.Areas(i), "Area" & i
Next i
Set Tester2 = OutputRanges
End Function

Public Sub test()
Dim Testarea as Range
Dim myValues As Variant
For i = 1 To Tester2.Count
Set Testarea = Tester2("Area" & i)
MsgBox Testarea.Address
Next i
End Sub

regards
Paul

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
Problem with getting numbers in some range values!? Ivica TypeR Excel Worksheet Functions 2 July 10th 07 01:29 AM
Stumped! Collecting values into one cell. AthleteTO Excel Worksheet Functions 5 November 2nd 04 04:24 PM
Stumped! Collecting values into one cell. AthleteTO Excel Worksheet Functions 0 November 1st 04 07:29 PM
Collecting values for later display? Ed[_9_] Excel Programming 4 August 4th 03 04:50 PM
collecting previous values adil Excel Programming 1 July 31st 03 04:31 PM


All times are GMT +1. The time now is 06:54 AM.

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

About Us

"It's about Microsoft Excel"