PC Review


Reply
Thread Tools Rate Thread

Dynamic Charting

 
 
=?Utf-8?B?c3RvbmUtbWFu?=
Guest
Posts: n/a
 
      20th Oct 2006
I frequently make simple date & total graphs using rolling 52 week sales
totals for different product lines. The dates are always in the top row
(D1:BC1). The totals are always the last row of those same columns (D though
BC). Unfortunately the last row can change depending upon the number of
products in that line. The recorded macro below works when the totals are on
the 6th row. I've been trying to modify this with some sort of “lastrow"
function to dynamically change the "D6:BC6" to the appropriate row, but so
far haven't been able to get anything I've tried to work. Please help.

Range("D1:BC1,D6:BC6").Select
Range("BC6").Activate
Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("week").Range("D1:BC1,D6:BC6")
ActiveChart.Location Where:=xlLocationAsObject, Name:="week"
ActiveChart.Axes(xlCategory).Select
With ActiveChart.Axes(xlCategory)
.MinimumScaleIsAuto = True
.MaximumScaleIsAuto = True
.BaseUnitIsAuto = True
.MajorUnitIsAuto = True
.MinorUnitIsAuto = True
.Crosses = xlAutomatic
.AxisBetweenCategories = True
.ReversePlotOrder = True
End With
 
Reply With Quote
 
 
 
 
gamma_007@yahoo.com
Guest
Posts: n/a
 
      20th Oct 2006
Try this at the start of to select the range

Dim r1, r2, myrange As Range

lrow = Range("D1").End(xlDown).Row
Set r1 = Range(Cells(1, 4), Cells(1, 55))
Set r2 = Range(Cells(lrow, 4), Cells(lrow, 55))
Set myrange = Union(r1, r2)
myrange.Select
Cells(lrow, 55).Activate

The xlDown only works if there are no blank rows until the end.

Then use this for your data source line

ActiveChart.SetSourceData Source:=myrange

stone-man wrote:
> I frequently make simple date & total graphs using rolling 52 week sales
> totals for different product lines. The dates are always in the top row
> (D1:BC1). The totals are always the last row of those same columns (D though
> BC). Unfortunately the last row can change depending upon the number of
> products in that line. The recorded macro below works when the totals are on
> the 6th row. I've been trying to modify this with some sort of "lastrow"
> function to dynamically change the "D6:BC6" to the appropriate row, but so
> far haven't been able to get anything I've tried to work. Please help.
>
> Range("D1:BC1,D6:BC6").Select
> Range("BC6").Activate
> Charts.Add
> ActiveChart.ChartType = xlLineMarkers
> ActiveChart.SetSourceData Source:=Sheets("week").Range("D1:BC1,D6:BC6")
> ActiveChart.Location Where:=xlLocationAsObject, Name:="week"
> ActiveChart.Axes(xlCategory).Select
> With ActiveChart.Axes(xlCategory)
> .MinimumScaleIsAuto = True
> .MaximumScaleIsAuto = True
> .BaseUnitIsAuto = True
> .MajorUnitIsAuto = True
> .MinorUnitIsAuto = True
> .Crosses = xlAutomatic
> .AxisBetweenCategories = True
> .ReversePlotOrder = True
> End With


 
Reply With Quote
 
=?Utf-8?B?c3RvbmUtbWFu?=
Guest
Posts: n/a
 
      23rd Oct 2006
Thanks. That's just what I needed !

"(E-Mail Removed)" wrote:

> Try this at the start of to select the range
>
> Dim r1, r2, myrange As Range
>
> lrow = Range("D1").End(xlDown).Row
> Set r1 = Range(Cells(1, 4), Cells(1, 55))
> Set r2 = Range(Cells(lrow, 4), Cells(lrow, 55))
> Set myrange = Union(r1, r2)
> myrange.Select
> Cells(lrow, 55).Activate
>
> The xlDown only works if there are no blank rows until the end.
>
> Then use this for your data source line
>
> ActiveChart.SetSourceData Source:=myrange
>
> stone-man wrote:
> > I frequently make simple date & total graphs using rolling 52 week sales
> > totals for different product lines. The dates are always in the top row
> > (D1:BC1). The totals are always the last row of those same columns (D though
> > BC). Unfortunately the last row can change depending upon the number of
> > products in that line. The recorded macro below works when the totals are on
> > the 6th row. I've been trying to modify this with some sort of "lastrow"
> > function to dynamically change the "D6:BC6" to the appropriate row, but so
> > far haven't been able to get anything I've tried to work. Please help.
> >
> > Range("D1:BC1,D6:BC6").Select
> > Range("BC6").Activate
> > Charts.Add
> > ActiveChart.ChartType = xlLineMarkers
> > ActiveChart.SetSourceData Source:=Sheets("week").Range("D1:BC1,D6:BC6")
> > ActiveChart.Location Where:=xlLocationAsObject, Name:="week"
> > ActiveChart.Axes(xlCategory).Select
> > With ActiveChart.Axes(xlCategory)
> > .MinimumScaleIsAuto = True
> > .MaximumScaleIsAuto = True
> > .BaseUnitIsAuto = True
> > .MajorUnitIsAuto = True
> > .MinorUnitIsAuto = True
> > .Crosses = xlAutomatic
> > .AxisBetweenCategories = True
> > .ReversePlotOrder = True
> > End With

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamic charting brian.baker13@googlemail.com Microsoft Excel Charting 3 11th Nov 2007 02:16 PM
dynamic charting brian.baker13@googlemail.com Microsoft Excel Discussion 0 10th Nov 2007 03:36 PM
dynamic charting brian.baker13@googlemail.com Microsoft Excel Discussion 1 10th Nov 2007 03:31 PM
Dynamic Charting Richard Flame Microsoft Excel Charting 3 3rd Jul 2006 06:39 PM
Dynamic Charting sergv Microsoft Excel Misc 2 2nd Sep 2005 04:43 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:15 PM.