Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
daniel chen
 
Posts: n/a
Default Problem with chart creation

Sheet1 was populated with column arrays in Range("A8:J50").
I wanted to creat a chart for column array as specified in cells A1, A2, A3
as rowbegin, rowend,and columnofinterest respectively.
Soon after the chart was created all the values in Cells(*, *) were lost,
and the macro ceased to function properly.
Can you help me?

Sub Creat_a_chart()
Dim rowbegin, rowend, columnofinterest As Double

Cells(1, 1) = 8 ' as given example
Cells(2, 1) = 20 ' as given example
Cells(3, 1) = 3 ' as given example
rowbegin = Cells(1, 1)
rowend = Cells(2, 1)
columnofinterest = Cells(3, 1)
Range(Cells(rowbegin, columnofinterest), _
Cells(rowend, columnofinterest)).Select
Charts.Add
' From this point on, all the Cells(*, *) failed _ stating "Method
'Cells' of object '_Global' failed "

ActiveChart.ChartType = xlLineMarkers
On Error Resume Next
ActiveChart.SetSourceData Source:=_
Sheets("Sheet1").Range(Cells(rowbegin, columnofinterest), _
Cells(rowend, columnofinterest)), PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"
ActiveChart.HasLegend = False
Cells(1, 2) = Cells(1, 1) ' value lost
Cells(2, 2) = Cells(2, 1) ' value lost
Cells(3, 2) = Cells(3, 1) ' value lost
End Sub


  #2   Report Post  
Posted to microsoft.public.excel.misc
Jim Cone
 
Posts: n/a
Default Problem with chart creation

daniel,

"Charts.Add" creates a new chart sheet, which becomes the active sheet.
"Cells", with no sheet qualifier, refers to the active sheet.
There are no cells on a chart sheet.

'-----------------
Sub Create_a_chart()
Dim rowBegin as Long
Dim rowEnd as Long
Dim columnOfInterest As Long
Dim objSheet as Excel.Worksheet

Set objSheet = ActiveSheet
objSheet.Cells(1, 1).Value = 8
'etc
'--------------------------

Regards,
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"daniel chen" wrote in message ...
Sheet1 was populated with column arrays in Range("A8:J50").
I wanted to creat a chart for column array as specified in cells A1, A2, A3
as rowbegin, rowend,and columnofinterest respectively.
Soon after the chart was created all the values in Cells(*, *) were lost,
and the macro ceased to function properly.
Can you help me?

Sub Creat_a_chart()
Dim rowbegin, rowend, columnofinterest As Double

Cells(1, 1) = 8 ' as given example
Cells(2, 1) = 20 ' as given example
Cells(3, 1) = 3 ' as given example
rowbegin = Cells(1, 1)
rowend = Cells(2, 1)
columnofinterest = Cells(3, 1)
Range(Cells(rowbegin, columnofinterest), _
Cells(rowend, columnofinterest)).Select
Charts.Add
' From this point on, all the Cells(*, *) failed _ stating "Method
'Cells' of object '_Global' failed "

ActiveChart.ChartType = xlLineMarkers
On Error Resume Next
ActiveChart.SetSourceData Source:=_
Sheets("Sheet1").Range(Cells(rowbegin, columnofinterest), _
Cells(rowend, columnofinterest)), PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"
ActiveChart.HasLegend = False
Cells(1, 2) = Cells(1, 1) ' value lost
Cells(2, 2) = Cells(2, 1) ' value lost
Cells(3, 2) = Cells(3, 1) ' value lost
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.misc
daniel chen
 
Posts: n/a
Default Problem with chart creation

Hi Jim,
Thanks for the explanation. I have it working.

"Jim Cone" wrote in message
...
daniel,

"Charts.Add" creates a new chart sheet, which becomes the active sheet.
"Cells", with no sheet qualifier, refers to the active sheet.
There are no cells on a chart sheet.

'-----------------
Sub Create_a_chart()
Dim rowBegin as Long
Dim rowEnd as Long
Dim columnOfInterest As Long
Dim objSheet as Excel.Worksheet

Set objSheet = ActiveSheet
objSheet.Cells(1, 1).Value = 8
'etc
'--------------------------

Regards,
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"daniel chen" wrote in message
...
Sheet1 was populated with column arrays in Range("A8:J50").
I wanted to creat a chart for column array as specified in cells A1, A2,
A3
as rowbegin, rowend,and columnofinterest respectively.
Soon after the chart was created all the values in Cells(*, *) were lost,
and the macro ceased to function properly.
Can you help me?

Sub Creat_a_chart()
Dim rowbegin, rowend, columnofinterest As Double

Cells(1, 1) = 8 ' as given example
Cells(2, 1) = 20 ' as given example
Cells(3, 1) = 3 ' as given example
rowbegin = Cells(1, 1)
rowend = Cells(2, 1)
columnofinterest = Cells(3, 1)
Range(Cells(rowbegin, columnofinterest), _
Cells(rowend, columnofinterest)).Select
Charts.Add
' From this point on, all the Cells(*, *) failed _ stating "Method
'Cells' of object '_Global' failed "

ActiveChart.ChartType = xlLineMarkers
On Error Resume Next
ActiveChart.SetSourceData Source:=_
Sheets("Sheet1").Range(Cells(rowbegin, columnofinterest), _
Cells(rowend, columnofinterest)), PlotBy:=xlColumns
ActiveChart.Location Whe=xlLocationAsObject, Name:="Sheet1"
ActiveChart.HasLegend = False
Cells(1, 2) = Cells(1, 1) ' value lost
Cells(2, 2) = Cells(2, 1) ' value lost
Cells(3, 2) = Cells(3, 1) ' value lost
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
Very strange problem when inserting a picture in a 3D Chart DDearborn Charts and Charting in Excel 0 January 5th 06 05:36 PM
Chart Auto Expand Problem Mike Fox Excel Discussion (Misc queries) 0 January 2nd 06 10:58 AM
Title Block in Excel Chart - Size problem Stuart Saich Charts and Charting in Excel 1 October 25th 05 11:44 AM
Excel chart problem Mike1 Excel Worksheet Functions 0 September 13th 05 10:48 PM
Problem with Chart Title Formatting KvnLynch Charts and Charting in Excel 1 January 12th 05 03:15 AM


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

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"