Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Adding ranges

Hello,
I am creating a pie chart and I only want to plot the ranges that
correspond to values greater than 0. So I'd like to loop over the possible
entries and set my chart range to correspong to only those that are non-
zero. I'm assuming that I'll need to add ranges somehow to do this, but I
can't seem to get it right. How do you add ranges so that they can be used
for charts?

Here is an example of what I mean:


| A | B
_________________________
1 | name1 | 5
2 | name2 | 0
3 | name3 | 3
4 | name4 | 7



So I'd want the range to be "A1:B1,A3:B4" for my pie chart. I'd like to
loop over rows 1 through 4, and add the ranges corresponding to the non-
zero entries in column B.

Here is the loop that I created:

For i = 3 To 10
If Worksheets("Program").Cells(i, 12) 0 Then
Set PieChartRange = PieChartRange + Worksheets("Program").Range
(Cells(i, 11), Cells(i, 12))
End If
Next i


But the statement 'Set PieChartRange = ...' doesn't work. I'd like to use
that variable in the following block:


With ActiveSheet.ChartObjects.Add _
(Left:=440, Width:=330, Top:=495, Height:=220)
With .Chart
.SetSourceData Source:=ActiveSheet.Range(PieChartRange.Address)
'....
'....


I'd greatly appreciate any help.

--
Message posted via http://www.officekb.com
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding ranges

Can you hide the rows with zero. If you can, there is an option to no plot
hidden rows.

If you can't do that, then you will need to set up a second contiguous area
where you build your data with no zero cell data and use that as the source
for your chart.

--
Regards,
Tom Ogilvy

"Bryan via OfficeKB.com" wrote in message
...
Hello,
I am creating a pie chart and I only want to plot the ranges that
correspond to values greater than 0. So I'd like to loop over the

possible
entries and set my chart range to correspong to only those that are non-
zero. I'm assuming that I'll need to add ranges somehow to do this, but I
can't seem to get it right. How do you add ranges so that they can be

used
for charts?

Here is an example of what I mean:


| A | B
_________________________
1 | name1 | 5
2 | name2 | 0
3 | name3 | 3
4 | name4 | 7



So I'd want the range to be "A1:B1,A3:B4" for my pie chart. I'd like to
loop over rows 1 through 4, and add the ranges corresponding to the non-
zero entries in column B.

Here is the loop that I created:

For i = 3 To 10
If Worksheets("Program").Cells(i, 12) 0 Then
Set PieChartRange = PieChartRange + Worksheets("Program").Range
(Cells(i, 11), Cells(i, 12))
End If
Next i


But the statement 'Set PieChartRange = ...' doesn't work. I'd like to use
that variable in the following block:


With ActiveSheet.ChartObjects.Add _
(Left:=440, Width:=330, Top:=495, Height:=220)
With .Chart
.SetSourceData Source:=ActiveSheet.Range(PieChartRange.Address)
'....
'....


I'd greatly appreciate any help.

--
Message posted via http://www.officekb.com



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Adding ranges

Actually, I just got help from someone else on how to do this:

-----------
Dim myChartRange As Range
With Selection
For k = 1 To .Rows.Count
If .Cells(k, 2) 0 Then
If myChartRange Is Nothing Then
Set myChartRange = .Rows(k)
Else
Set myChartRange = Union(myChartRange, .Rows(k))
End If
End If
Next
End With
-----------

Thanks anyway.

--
Message posted via http://www.officekb.com
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Adding ranges

Yes, that will work for a single series category style chart and I guess
that is what you have. Glad you have a solution.

--
regards,
Tom Ogilvy

"Bryan via OfficeKB.com" wrote in message
...
Actually, I just got help from someone else on how to do this:

-----------
Dim myChartRange As Range
With Selection
For k = 1 To .Rows.Count
If .Cells(k, 2) 0 Then
If myChartRange Is Nothing Then
Set myChartRange = .Rows(k)
Else
Set myChartRange = Union(myChartRange, .Rows(k))
End If
End If
Next
End With
-----------

Thanks anyway.

--
Message posted via http://www.officekb.com



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
adding numbers that contain ranges Fyrfytr Excel Worksheet Functions 3 September 21st 06 08:52 AM
Adding Non-Contiguous Ranges COE Excel Discussion (Misc queries) 11 January 24th 06 11:43 PM
adding ranges [email protected] Excel Discussion (Misc queries) 2 November 21st 05 04:22 PM
adding named ranges Mike EHB-Docks New Users to Excel 7 April 8th 05 01:53 PM
Adding Cell Values to Ranges Mike R Excel Programming 2 August 1st 03 09:37 AM


All times are GMT +1. The time now is 08:11 PM.

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"