#1   Report Post  
Posted to microsoft.public.excel.misc
Joe Joe is offline
external usenet poster
 
Posts: 476
Default Column range...

Hi,

Columns B and C are dynamic (# values/#entries will vary) and the code
should set the source data accordingly for the graph.

In the code below, it changes the value of Column B ONLY, But Column C is
not considered it stops way above the enod of value (example if the last cell
with value is C45, it might stop at C40 etc), as I do not know the cell#
(last cell with value), I do not want to hardcode to value to 65000, which
will skew my graph.

Appreciate any help.

*******************************
Sub SetDataSource()

Dim NewSet1 As String
Dim NewSet2 As String
Dim CurLocation As String
CurLocation = ActiveCell.Address
NewSet1 = "B2:" & Range("B2").End(xlDown).Address
NewSet2 = "C2:" & Range("C2").End(xlDown).Address

ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.PlotArea.Select
ActiveChart.SetSourceData _
Source:=Union(Sheets(ActiveSheet.Name).Range(NewSe t1), _
Sheets(ActiveSheet.Name).Range(NewSet2))

Range(CurLocation).Select

End Sub

**************************


  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,365
Default Column range...

If you know that only data is in a column (i.e., no comments or non-graphable
info in that column) try something like:

NewSet2 = "C2:" & range("C" & Rows.Count).End(xlUp).Address

The Rows.Count keeps you from hard coding the 65000 and makes it flexible
enough to move to other versions of Excel. Nice trick that I was just clued
into here in these forums recently.

"Joe" wrote:

Hi,

Columns B and C are dynamic (# values/#entries will vary) and the code
should set the source data accordingly for the graph.

In the code below, it changes the value of Column B ONLY, But Column C is
not considered it stops way above the enod of value (example if the last cell
with value is C45, it might stop at C40 etc), as I do not know the cell#
(last cell with value), I do not want to hardcode to value to 65000, which
will skew my graph.

Appreciate any help.

*******************************
Sub SetDataSource()

Dim NewSet1 As String
Dim NewSet2 As String
Dim CurLocation As String
CurLocation = ActiveCell.Address
NewSet1 = "B2:" & Range("B2").End(xlDown).Address
NewSet2 = "C2:" & Range("C2").End(xlDown).Address

ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.PlotArea.Select
ActiveChart.SetSourceData _
Source:=Union(Sheets(ActiveSheet.Name).Range(NewSe t1), _
Sheets(ActiveSheet.Name).Range(NewSet2))

Range(CurLocation).Select

End Sub

**************************


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
macro unouwanme Excel Discussion (Misc queries) 9 August 31st 06 09:38 PM
Return SEARCHED Column Number of Numeric Label and Value Sam via OfficeKB.com Excel Worksheet Functions 23 January 30th 06 06:16 PM
How to count dates within a certain range in a column with mutiple date range entries Krisjhn Excel Worksheet Functions 2 September 1st 05 01:59 PM
Program Column B to record numerical range based on number in colm Nikole Excel Discussion (Misc queries) 2 August 17th 05 08:37 PM
Match function...random search? Les Excel Worksheet Functions 10 July 28th 05 11:54 AM


All times are GMT +1. The time now is 08:26 AM.

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

About Us

"It's about Microsoft Excel"