Graph not plotting correctly if source not selected

Here my code:

Set Cht_level = Charts.Add
With Cht_level
   .ChartType = xlLine
   .SetSourceData Source:=cht_src
End With

if fails.

But if I

add cht_src.Select

before the code, it works brilliantly?

Why?
0
Frank
6/6/2010 5:12:40 PM
excel.programming 6508 articles. 1 followers. Follow

5 Replies
1319 Views

Similar Articles

[PageSpeed] 36

Frank  -

Excel chart guru Jon Peltier has VBA code examples at

http://peltiertech.com/Excel/ChartsHowTo/QuickChartVBA.html

-  Mike
http://www.MikeMiddleton.com
Mike@DecisionToolworks.com


"Frank" <no.reply7@comcast.net> wrote in message 
news:ab71f33a-679d-4c45-871e-435fadb31fbc@j36g2000prj.googlegroups.com...
> Here my code:
>
> Set Cht_level = Charts.Add
> With Cht_level
>   .ChartType = xlLine
>   .SetSourceData Source:=cht_src
> End With
>
> if fails.
>
> But if I
>
> add cht_src.Select
>
> before the code, it works brilliantly?
>
> Why? 

0
Mike
6/6/2010 7:47:19 PM
How is cht_src defined?

- Jon
-------
Jon Peltier
Peltier Technical Services, Inc.
http://peltiertech.com/


On 6/6/2010 1:12 PM, Frank wrote:
> Here my code:
>
> Set Cht_level = Charts.Add
> With Cht_level
>     .ChartType = xlLine
>     .SetSourceData Source:=cht_src
> End With
>
> if fails.
>
> But if I
>
> add cht_src.Select
>
> before the code, it works brilliantly?
>
> Why?
0
Jon
6/7/2010 2:59:09 PM
Hi Jon

I've actaully look at your site. It look you set the chart source as
selection.

Here is my non-working code"

Set cht_src = Range(Range("A1").Offset(1, 2 * (c + 1) + 2),
Range("A1").Offset(Application.Count(Range("dist_x_axys")) + 1, 2 * (c
+ 1) + 2 + c))

Set Cht_level = Charts.Add
With Cht_level
   .ChartType = xlLine
   .SetSourceData Source:=cht_src
End With


here is my working code:

Set cht_src = Range(Range("A1").Offset(1, 2 * (c + 1) + 2),
Range("A1").Offset(Application.Count(Range("dist_x_axys")) + 1, 2 * (c
+ 1) + 2 + c))

cht_src.Select

Set Cht_level = Charts.Add
With Cht_level
   .ChartType = xlLine
   .SetSourceData Source:=cht_src
End With

The only difference is the cht_src.Select

I find it odd that you need to select the chart source in order to
graph it correctly.
0
Frank
6/7/2010 3:55:15 PM
Frank -

I find this strange too.

What if you remove the .Select statement, then move .ChartType after 
..SetSourceData?

- Jon
-------
Jon Peltier
Peltier Technical Services, Inc.
http://peltiertech.com/


On 6/7/2010 11:55 AM, Frank wrote:
> Hi Jon
>
> I've actaully look at your site. It look you set the chart source as
> selection.
>
> Here is my non-working code"
>
> Set cht_src = Range(Range("A1").Offset(1, 2 * (c + 1) + 2),
> Range("A1").Offset(Application.Count(Range("dist_x_axys")) + 1, 2 * (c
> + 1) + 2 + c))
>
> Set Cht_level = Charts.Add
> With Cht_level
>     .ChartType = xlLine
>     .SetSourceData Source:=cht_src
> End With
>
>
> here is my working code:
>
> Set cht_src = Range(Range("A1").Offset(1, 2 * (c + 1) + 2),
> Range("A1").Offset(Application.Count(Range("dist_x_axys")) + 1, 2 * (c
> + 1) + 2 + c))
>
> cht_src.Select
>
> Set Cht_level = Charts.Add
> With Cht_level
>     .ChartType = xlLine
>     .SetSourceData Source:=cht_src
> End With
>
> The only difference is the cht_src.Select
>
> I find it odd that you need to select the chart source in order to
> graph it correctly.
0
Jon
6/7/2010 3:59:54 PM
Yep!

That works.

I'm learning every day.

Thanks
0
Frank
6/7/2010 4:49:35 PM
Reply:

Similar Artilces:

Make lines on a graph appear with a button
All, I need to create a graph with 40 or so lines graphed but only one up o the graph at a time with the use of buttons. I would really appreciat a hand, I am very new to this level of Excel. Thanks -- Message posted from http://www.ExcelForum.com Select all the data, and create a line chart Select a cell in the table Choose Data>Filter>AutoFilter From the dropdown list in one of the heading cells, select an item The chart will display the data for that item geistritter < wrote: > I need to create a graph with 40 or so lines graphed but only one up on > the graph at a tim...

Object Source / Record Source
Hello I have created a database regarding the School System. I have created three forms (one form and two subforms) one main form is (Students) where i enter student's name, father's name, phone, address etc. now on the main Student form i want to place a subform. But the thing i want to know is: I want to make two buttons on my main form (Fees) and (Progress).. because i have two subforms (sbffees and sbfprogress) now the record source of subformbox should be controled with these two buttons. when i click the ( Fee) button the Source Object should be (sbf-fee) and when i c...

XY scatter graph
How do I attach dates to data points when the x&y values are not dates? Hi, One way is to use Rob Bobey's free addin, Chart Labeler. http://www.appspro.com/Utilities/ChartLabeler.htm Cheers Andy gps tech wrote: > How do I attach dates to data points when the x&y values are not dates? -- Andy Pope, Microsoft MVP - Excel http://www.andypope.info ...

html source code into Excel
Can anyone tell me how to (in VBA) get the source code for a web page into a string so that I can parse it? Note: I can't use a Query Table for this part as the data I need is imbedded into an href. Any help would be greatly appreciated. Thanks, Paul ...

Connecting to a shared SSRS data source from BIDS
I'm just starting out using BIDS and creating reports in general. I've been using Report Builder and have no trouble accessing a shared SSRS data source by specifying the Report Server (http://<Server>/ReportServer) in the Options...Settings, from there I can view and use any predefined data source in a report. How do I specify in BIDS that I wish to use a preconfigured shared data source from SSRS, I can't see any obvious option. Any advice gratefully received. Thanks David David, Hopefully when you connect your report to a shared datasource in design t...

Prediction Graphs
How do i make a graph predict the next value from 3 tables with info eg Table 1 has 5$ profit Table 2 has 3$ profit Table 3 has 8$ Profit how do i make a graph which predicts the next set of values from these values? -- peabushmartin ------------------------------------------------------------------------ peabushmartin's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=27399 View this thread: http://www.excelforum.com/showthread.php?threadid=469414 The mechanics of getting a chart to predict future values is easy. Chart your data in the desi...

Graph within a graph
I am looking to have a pie chart show general information and then have another pie chart show a section of the origional in greater detail. Is this possible? Have you tried using a Pie in Pie chart? "Jen Kulak" wrote: > I am looking to have a pie chart show general information and then have > another pie chart show a section of the origional in greater detail. Is this > possible? That is what I am trying to figure out how to do. I know where the option is, but for some reason I cannot figure out how to enter the data correctly. "Barb R." wrote: &g...

How does one correct an incorrect payment?
Here's what I am trying to figure out how to correct: I'm setup with auto-debit with my apartment building. This month, they were only supposed to withdraw $400 for rent, but accidentally withdrew $1100. They wrote me a check as a refund in the amount of $700. Via the auto-sync with my bank, MS Money 2006 downloaded both transactions. I could mark the $1100 dollars as "rent expense", and the $700 as "other income", but this wouldn't really be correct, as I didn't really pay that much for rent, and the reimbursement isn't really income. So how ...

sales graphs
How can I create a graph that would show sales/dept on the Y axis and years or months on the X axis? use a pivot chart/table in excel. You must create a datasource forst. "irene" <anonymous@discussions.microsoft.com> wrote in message news:260801c5113c$6dd4a6d0$a601280a@phx.gbl... > How can I create a graph that would show sales/dept on > the Y axis and years or months on the X axis? ...

Indicating selected cell
I have a worksheet set up with borders around the cells and when the cell is selected, it just shows a thin double line around 3 sides of the cell selected so it is hard to tell which cell is selected. Is there a way to shade or display the selected cell in a different color? LGuest, Try this out: http://www.cpearson.com/excel/RowLiner.htm John "LGuest" <LGBeach8@yahoo.com> wrote in message news:142201c3e031$0047f140$a301280a@phx.gbl... > I have a worksheet set up with borders around the cells > and when the cell is selected, it just shows a thin double > lin...

Access table data type selections
When creating a new database table I am not given an option for attachments in the drop down menu. Anyone know why and how I can correct it? I get the usuals "text, memo, date, number OLE object..." but no option for attachments???? Jim, Unless you are using the .ACCDB format you will not get that choice. Is that the case? -- Gina Whipp 2010 Microsoft MVP (Access) "I feel I have been denied critical, need to know, information!" - Tremors II http://www.regina-whipp.com/index_files/TipList.htm "Jim S" <JimS@discussions.microsoft...

Resizing Graphs
I have problems with Excel when there are tons of graphs i hve to create with all the graphs being on one page. Having to resize all of them when they are all ALREADY different sizes is a pain. I know how to hold down the control key and select them and resize them all at once, but some or still larger than others unless i resize them individually. Is there a way to make them all the same height adn width some how? or is this just a dream? Must i resize all of them individually? I personally use an add-in (.xla) which includes the following code (you can pick up the size of a chart with ctrl...

Creating a Line graph
I have data that I want to put in a simple line graph: The data is A B 23 200 87 500 I mark the 6 cells, select insert chart / line and get a chart with both A and B labels on the x axis. I go to "select data source" and try "switch row/column" and get A and B as series names in the legend. How do I get the label A and the values 23 and 87 on the x axis, and label B and values 200 and 500 on the y axis please? (Congratulations Microsoft for making something that was so easy and powerful in Excel 2003 an absolutely primitive disgrace...

validating company id against the source file
Version: GP Integration Manager 9.0 We have several different companies and the database id exist as a column in the source file. When we import, we want to make sure that these two match - and if not - then cancel the integration. Is there any way to figure out the company you are logged in before we run the integration manager? The problem is how do I get the input from GP saying what company it has running? Thanks, VJ you can use retrieveglobals9.dll to retrieve the company and even use that as a query criteria. Use this code in the Before integration script: ' Initialize glob...

Negative or zero values cannot be plotted correctly on log charts
Excel 2002 SP3. This maybe a stupid question (I'm not a statistician or mathematician). I have data that looks like this: Na 0.032617 Cl 0.0265 Ca 0.000524 K 0.005523 Mg 0.0000823 PO4 0.00031 HCO3 0.001655 I am plotting it with categorical values on the xaxis and the numerical value on the y axis. I am using a logarithmic scale for the y axis. I am getting the "Negative or zero values cannot be plotted correctly on log charts. Only positive values can be interpreted on a logarithmic scale" message, which I see from the newsgroup is common if there are zeros in the data. H...

Graphs on Forms
I am having a problem getting a graph to display the variables along the right axes. The graph sits on a form which is linked to a parent query. The graph's information comes from a separate crosstab query that is linked to the form via fields from the parent query. The graph fields are day (horizontal axis), race time (Y-axis) and race distance (series field). Unfortunately MS Graph automatically plots the day field as series and the race distance on the X-axis despite the fact that in the crosstab query, I have assigned 'day' as a column heading, 'race distance' as ...

How to show utf8 encoded csv file in excel correctly
Use Notepad to create a csv file: 1. Open Notepad, type °C (Alt 248 then C). Then save as test.csv with UTF8 encoding. In hex, it should read (ef bb bf c2 b0 43), where "ef bb bf" is BOM, "c2 b0" is the degree sign and "43" is C. 2. Double click this file, Excel opens it up. It shows °C in the first cell. Why? Why noy simply °C? 3. If I use the Open dialog to open the file, the "Text Import Wizard" shows up, showing the encoding correctly. Click finish, °C is shown in the first cell. 4. If I create the file using ...

The Reliable Source for Everything XML
The Reliable Source for Everything XML - XML 2005 Update XML 2005 - November 14-18 - Atlanta Hilton Hotel - Atlanta, GA www.xmlconference.org Register today and participate in IDEAlliance's XML 2005 Conference, the most respected educational gathering of technologists, novices, experienced implementers and users, consultants, and innovators to share knowledge and experiences, gain insight, and initiate new advancements in XML and related standards. XML 2005 is "the reliable source for everything XML". XML 2005 is five jam packed days of educational tutorials, high-level keynot...

How to Select a relative range with Using "Find" and Offset()
XL 2003 The following works fine: Sub OneCellText() Dim MyRange As Range Dim MyCell As Range Dim TempVar As String Set MyRange = Selection For Each MyCell In MyRange If MyCell.Value <> "" Then TempVar = TempVar + MyCell.Value + Chr(10) Next MyCell Range("E41").Formula = TempVar End Sub I would like to "compute" MyRange as follows: Cells.Find(What:="IMPACTED ACCOUNTS").Activate ActiveCell.Offset(1, 3).Range("A1:E10").Select Where things get tough is that the W/S that I review have ...

changing cell value depending on list selection
I have a long coloumn of data which is entered by selecting from a dro down list (data/validation/list)i want a numerical value to b associated with each value from the drop down list. I would also lik this value to be dependent on another value in another cell. ie: A B C one build 1 two three build 2 Coloumns A and B are drop down lists and C is a numerical value tha appears only when Build is in coloumn B and the value depends on wha is entered in coloumn A. Hope this isnt too confusing! Thanks Rober -- Message posted...

joining data points on graph
I am merging two graphs and one has 23 data points, the other has 9. The category axis will have 23 data points but the 9 points are spread out, i.e. they may be at points 1, 3, 7, 15 etc of the 23-point scale. At the moment the graph will only join points that are beside each other; how do I get them to connect to the points that have spaces between them? minihana wrote on Fri, 10 Feb 2006 11:29:04 -0800: m> I am merging two graphs and one has 23 data points, the m> other has 9. The category axis will have 23 data points but m> the 9 points are spread out, i.e. they may be...

How to support multiple selection in a tree control.
Platform: Windows 2000, VC++ .NET Hello, In my MDI application, I need to support deleting multiple items of a CTreeControl.However i can't select multiple items for deletion with the use of shift and ctrl key.As there is no provision to use shift and control key over tree.Is there some way I can support multiple selection of tree iteme? Any pointers or help would be of great use. Thanks and Regards Rinku. I have personally used part of the code in this one: http://www.techsoft.no/bendik/ This also seems reasonably good: http://www.codeguru.com/Cpp/controls/treeview/multiview/a...

Automatic Graphs/ Dynamic Graphs
I have a list of test results, one row for each participant. (Each result is in a seperate column) I need to make a graph of all of their results when I click on their names. Obvously I cannot create a graph for each one, as there could be hundreds of participants, I need it to create a graph using relevent cell references for each person on the fly. I have seen this done in the past, but am unsure on how to accomplish this myself. Thankyou for any help you can give me Dan Hi, Maybe you used one of these sites previous to get your information. http://peltiertech.com/Excel/Charts/Dy...

setting criteria for time values in select queries
I am using Access 2000 and 2003 (different locations). I have a need to be able to look at records entered in various time ranges eg. AM. AFT or PM. The underlying table has a time field with default set at Time(). On the data entry form the Time field shows the system time at time of entry. So does the select query I created to extract the data, until I input the criteria - Between #12:00:00PM# And #5:00:00PM#, when I run the query with this criteria I get no data at all, just the column headings. This format works well for seperating data for given days, confused as to why it wil...

Merge and Center and Center Accross Selection
What is the difference between Merge/Center and Center across selection? As far as i can tell they are the same thing. With the Merge/Center option you actually merge two or more cells into a single large cell with your data in the center of it. With Center Across Selection the selected cells all remain separate with the data merely displayed in the center. By the way, most Excel experts recommend avoiding merged cells as far as possible as they can cause problems with calculations, filtering, sorting etc. "Bojingles03" wrote: > What is the difference between Merge/Cente...