ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Naming a range and then use it to create chart (https://www.excelbanter.com/excel-programming/377662-naming-range-then-use-create-chart.html)

[email protected]

Naming a range and then use it to create chart
 
I have been struggling with this for hours and I seriously think this
is just a syntax error so if somebody can help me, I will really
appreciate it.

I check on previous topics in the discussion and I think this is the
right way to declare a name for range,

Let say in this case FNMACounter is 57 thus I want the range of A1:B57
as FNMARange
--------------------------------------------------------------------------------------------------------------------------------


Range(Cells(1, 1), Cells(FNMACounter, 2)).Name = "FNMARange"

----------------------------------------------------------------------------------------------------------------------------------

And then I used macro to create the chart,


Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("FNMA
temp").Range("FNMARange"), _
PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:="Main Data"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "FNMA Chart"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text =
"Maturity Dates"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Yield"
End With
ActiveChart.HasLegend = False

somehow it keeps getting me application or object defined error, does
anybody know whats wrong with my code. Thank you!


AndrewArmstrong

Naming a range and then use it to create chart
 
When you get the error and click "debug", what line is highlighted?

wrote:
I have been struggling with this for hours and I seriously think this
is just a syntax error so if somebody can help me, I will really
appreciate it.

I check on previous topics in the discussion and I think this is the
right way to declare a name for range,

Let say in this case FNMACounter is 57 thus I want the range of A1:B57
as FNMARange
--------------------------------------------------------------------------------------------------------------------------------


Range(Cells(1, 1), Cells(FNMACounter, 2)).Name = "FNMARange"

----------------------------------------------------------------------------------------------------------------------------------

And then I used macro to create the chart,


Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("FNMA
temp").Range("FNMARange"), _
PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:="Main Data"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "FNMA Chart"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text =
"Maturity Dates"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Yield"
End With
ActiveChart.HasLegend = False

somehow it keeps getting me application or object defined error, does
anybody know whats wrong with my code. Thank you!



AndrewArmstrong

Naming a range and then use it to create chart
 
Why don't you try selecting the range like this:

Range("a1:b"& FNMACounter)

AndrewArmstrong wrote:
When you get the error and click "debug", what line is highlighted?

wrote:
I have been struggling with this for hours and I seriously think this
is just a syntax error so if somebody can help me, I will really
appreciate it.

I check on previous topics in the discussion and I think this is the
right way to declare a name for range,

Let say in this case FNMACounter is 57 thus I want the range of A1:B57
as FNMARange
--------------------------------------------------------------------------------------------------------------------------------


Range(Cells(1, 1), Cells(FNMACounter, 2)).Name = "FNMARange"

----------------------------------------------------------------------------------------------------------------------------------

And then I used macro to create the chart,


Charts.Add
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SetSourceData Source:=Sheets("FNMA
temp").Range("FNMARange"), _
PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:="Main Data"
With ActiveChart
.HasTitle = True
.ChartTitle.Characters.Text = "FNMA Chart"
.Axes(xlCategory, xlPrimary).HasTitle = True
.Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text =
"Maturity Dates"
.Axes(xlValue, xlPrimary).HasTitle = True
.Axes(xlValue, xlPrimary).AxisTitle.Characters.Text = "Yield"
End With
ActiveChart.HasLegend = False

somehow it keeps getting me application or object defined error, does
anybody know whats wrong with my code. Thank you!




All times are GMT +1. The time now is 12:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com