Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default XValues with variable end row


I am having trouble determining the best way to code the x-axis for my
chart. The beginning of the x axis will always be located in cell H2.
The end of the range will be in column H and some row which is declared
as variable "LastRow". I have tried multiple formats for declaring
this range.

I have attempted to resolve this by using multiple formats as well as
using an XY scatter plot. The y values for the multiple signals are
selected using shift end right and shift end down (from cell "J1").
This has proven to be a robust way to select all of my data for
graphing but I can't seem to get the appropriate x-axis (time scale) on
my graph.


Code:
--------------------
Range("J1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Charts.Add
ActiveChart.ChartType = xlLine
--------------------


I have tried the following methods to format x axis (as well as many
others).


Code:
--------------------
ActiveChart.SeriesCollection(1).XValues = "=RunData!R2C8:R & LastRowC8"

ActiveChart.SeriesCollection(1).XValues = Worksheets("RunData").Range(Cells(2, 8), Cells(LastRow, 8))
--------------------


This is my first post and have found the archive to be quite usefull on
many occations. I love this website! Any help from the Excel masters
will be greatly appreciated!


--
BStanton
------------------------------------------------------------------------
BStanton's Profile: http://www.excelforum.com/member.php...o&userid=19220
View this thread: http://www.excelforum.com/showthread...hreadid=375662

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default XValues with variable end row


Hello

you may try


Dim Plage As Range
Set Plage = Worksheets("RunData").Range(Cells(2, 8), Cells(LastRow,
8))
ActiveChart.SeriesCollection(1).XValues = Plage

or

Dim Plage As Range
Set Plage = Worksheets("RunData").Range("H2:H" & LastRow)
ActiveChart.SeriesCollection(1).XValues = Plage


I hope this help you
Regards ,
michel


--
michelxld
------------------------------------------------------------------------
michelxld's Profile: http://www.excelforum.com/member.php...o&userid=17367
View this thread: http://www.excelforum.com/showthread...hreadid=375662

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default XValues with variable end row


No that didn't seem to work either.
Is Plage an object that needs to be defined?


--
BStanton
------------------------------------------------------------------------
BStanton's Profile: http://www.excelforum.com/member.php...o&userid=19220
View this thread: http://www.excelforum.com/showthread...hreadid=375662

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default XValues with variable end row


Hello

this complete example works for me ( Excel2002 ) but perhaps i didn't
understand your problem


Sub testGraph()
Dim Plage As Range, Plage2 As Range
Dim LastRow As Integer, LineSource As Integer
Dim ColumnSource As Byte

'*****XValues with variable end row in column H *****
LastRow = Worksheets("RunData").Range("H65536").End(xlUp).Ro w
Set Plage = Worksheets("RunData").Range(Cells(2, 8), Cells(LastRow,
8))
'*******

'*** data source : end right and shift end down (from cell "J1")******
LineSource = Worksheets("RunData").Range("J1").End(xlDown).Row
ColumnSource = Worksheets("RunData").Range("J1").End(xlToRight).C olumn
Set Plage2 = Range(Cells(1, 10), Cells(LineSource, ColumnSource))
'*********

Charts.Add
ActiveChart.ChartType = xlLine

With ActiveChart
..SetSourceData Source:=Plage2
..SeriesCollection(1).XValues = Plage
..Location Whe=xlLocationAsNewSheet
End With

End Sub


Regards ,
michel


--
michelxld
------------------------------------------------------------------------
michelxld's Profile: http://www.excelforum.com/member.php...o&userid=17367
View this thread: http://www.excelforum.com/showthread...hreadid=375662

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default XValues with variable end row

"BStanton" wrote in message

I have tried the following methods to format x axis (as well as many
others).


Code:
--------------------
ActiveChart.SeriesCollection(1).XValues = "=RunData!R2C8:R &

LastRowC8"

ActiveChart.SeriesCollection(1).XValues =

Worksheets("RunData").Range(Cells(2, 8), Cells(LastRow, 8))
--------------------


Your first line will always fail, the second should work providing
Worksheets("RunData") is the active sheet. If not you need to qualify the
Cells to the sheet, eg

Dim rXvals As Range

With Worksheets("Sheet2")
LastRow = .Cells(65536, 8).End(xlUp).Row
'or
LastRow = .Cells(2, 8).End(xlDown).Row

Set rXvals = Range(.Cells(2, 8), .Cells(LastRow, 8))
'or
'Set rXvals = Range(.Cells(2, 8), .Cells(65536, 8).End(xlUp))
'Set rXvals = Range(.Cells(2, 8), .Cells(2, 8).End(xlDown))
End With

With ActiveChart
..SeriesCollection(1).XValues = rXvals
End With

If you use Dynamic Names to refer to your X & Y values you will not need any
code to update your chart as data expands.

Regards,
Peter T




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
.Values / .XValues modification baconcow Excel Discussion (Misc queries) 4 September 29th 08 11:06 PM
.XValues syntax problem JF_01 Charts and Charting in Excel 1 December 19th 05 08:21 PM
Unable to set the XValues Property Ali Baba Charts and Charting in Excel 2 September 14th 05 04:54 AM
XValues and values. y Excel Programming 3 April 10th 04 03:13 AM
Displaying XValues. y Excel Programming 2 April 9th 04 07:27 PM


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