|
-
Apr 8th, 2008, 10:37 AM
#1
Expanding Excel Ranges
How does one go about expanding a defined Excel Range? I have it defined as:
Code:
Dim TempRange As Excel.Range = Globals.Sheet1.Range("E4:P4")
Now what I want to do is add items into that range. In actuality, I need to add "P4" at the beginning, and "E4" at the end of TempRange, keeping all of the items in the original TempRange as well (two items on top of the total cells in TempRange). Is there an easy way to assign an array of values and put it back into an Excel.Range object?
Using VS 2008, Excel 2007, VSTO.
-
Apr 8th, 2008, 01:01 PM
#2
Re: Expanding Excel Ranges
"E4:P4" are 12 items... I want a range of 14 items, with P4 at the beginning and E4 at the end... with the original 12 items in between.
-
Apr 8th, 2008, 02:18 PM
#3
Re: Expanding Excel Ranges
Well when I try that, it still doesn't do what is intended.
Code:
Dim TempRange As Excel.Range = Globals.Sheet1.Range("P4,E4:P4,E4")
The E4:P4 range actually gets plotted first, then P4 and E4.
-
Apr 8th, 2008, 02:40 PM
#4
Re: Expanding Excel Ranges
Yes, it does show 14 items, but the problem is that I am trying to chart these values. When you try to add that range to a series, it does show the 14 values, but the "E4:P4" selection is always plotted first, even though "P4" was first in that selection string.
Code:
Dim TempRange As Excel.Range = Globals.Sheet1.Range("P4,E4:P4,E4")
Dim MySeriesColl As Excel.SeriesCollection = MyChart.SeriesCollection
Dim TempSeries As Excel.Series = MySeriesColl.Add(TempRange)
TempSeries.Name = "Temperature"
TempSeries.AxisGroup = Excel.XlAxisGroup.xlPrimary
No matter what you put for the range, the "E4:P4" part is plotted first, with the single "P4" and "E4" values at the end. I want them in the order specified, and it doesn't want to work grrrrrrrr
-
Apr 8th, 2008, 04:53 PM
#5
Re: Expanding Excel Ranges
you can use join to combine ranges
something like
set myrange = join(myrange, range("f7:g99"))
for this example myrange must be an existing range
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Apr 8th, 2008, 07:44 PM
#6
Re: Expanding Excel Ranges
Use different method and syntax that may help:
Code:
Dim MySeriesColl As Excel.SeriesCollection = MyChart.SeriesCollection
Dim TempSeries As Excel.Series = MySeriesColl.NewSeries
TempSeries.Name = "Temperature"
TempSeries.Values = "=(Globals.Sheet1!R4C16,Globals.Sheet1!R4C5:R4C16,Globals.Sheet1!R4C5)"
TempSeries.AxisGroup = Excel.XlAxisGroup.xlPrimary
R4C16 is "P4", R4C5:R4C16 is "E4:P4", R4C5 is "E4"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|