Help Programming an XY scatter Chart #2

I have a user form that inputs data onto a spreadsheet. I have a
command button that runs a macro that activates the sheet, selects the
data, and creates the XY Scatter chart. My Problem is that I don't know
how to set a loop to set each series' properties . (The number of
series changes every time) Bellow is an example where I manually set
the properties for three of the series. Any Ideas on how to create a
loop to set all.

Range("A:A,C:C,D:D").Select
    Range("D1").Activate
    Charts.Add
    ActiveChart.ChartType = xlXYScatter
    ActiveChart.SetSourceData
Source:=Sheets("Sheet1").Range("A1:A15,C1:D15"), _
        PlotBy:=xlRows
    ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R2C4"
    ActiveChart.SeriesCollection(1).Values = "=Sheet1!R2C3"
    ActiveChart.SeriesCollection(1).name = "=Sheet1!R2C1"
    ActiveChart.SeriesCollection(2).XValues = "=Sheet1!R3C4"
    ActiveChart.SeriesCollection(2).Values = "=Sheet1!R3C3"
    ActiveChart.SeriesCollection(2).name = "=Sheet1!R3C1"
    ActiveChart.SeriesCollection(3).XValues = "=Sheet1!R4C4"
    ActiveChart.SeriesCollection(3).Values = "=Sheet1!R4C3"
    ActiveChart.SeriesCollection(3).name = "=Sheet1!R4C1"
    ActiveChart.Location Where:=xlLocationAsNewSheet, name:="xyCart"
    With ActiveChart
        .HasTitle = True
        .ChartTitle.Characters.Text = "risk"
        .Axes(xlCategory, xlPrimary).HasTitle = True
        .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text =
"Impact"
        .Axes(xlValue, xlPrimary).HasTitle = True
        .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text =
"Probability"
    End With
    With ActiveChart
        .HasAxis(xlCategory, xlPrimary) = False
        .HasAxis(xlValue, xlPrimary) = False
    End With
    ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
    With ActiveChart.Axes(xlCategory)
        .HasMajorGridlines = True
        .HasMinorGridlines = False
    End With
    With ActiveChart.Axes(xlValue)
        .HasMajorGridlines = True
        .HasMinorGridlines = False
    End With
    ActiveChart.HasLegend = False
End Sub

0
3/21/2006 10:15:18 PM
excel.charting 18370 articles. 0 followers. Follow

6 Replies
881 Views

Similar Articles

[PageSpeed] 37

This procedure does what you asked. Note that there are still a few 
redundant and unneeded steps (the chart recorder records even default 
settings).

Sub DoTheChart()
  Dim WS As Worksheet
  Dim Cht As Chart
  Dim Rng As Range
  Dim iRow As Long

  Set WS = ActiveSheet
  Set Cht = Charts.Add
  Cht.ChartType = xlXYScatter

  Set Rng = WS.Range(WS.Range("A2"), WS.Range("A2").End(xlDown))
  For iRow = 2 To 1 + Rng.Rows.Count
    Cht.SeriesCollection.NewSeries
    With Cht.SeriesCollection(iRow - 1)
      .XValues = "='" & WS.Name & "'!R" & iRow & "C4"
      .Values = "='" & WS.Name & "'!R" & iRow & "C3"
      .Name = "='" & WS.Name & "'!R" & iRow & "C1"
    End With
  Next
  With Cht
    .HasTitle = True
    .ChartTitle.Text = "risk"
    .Axes(xlCategory, xlPrimary).HasTitle = True
    .Axes(xlCategory, xlPrimary).AxisTitle.Text = "Impact"
    .Axes(xlValue, xlPrimary).HasTitle = True
    .Axes(xlValue, xlPrimary).AxisTitle.Text = "Probability"
    .HasAxis(xlCategory, xlPrimary) = False
    .HasAxis(xlValue, xlPrimary) = False
  End With
  With Cht.Axes(xlCategory)
    .HasMajorGridlines = True
    .HasMinorGridlines = False
  End With
  With Cht.Axes(xlValue)
    .HasMajorGridlines = True
    .HasMinorGridlines = False
  End With
  Cht.HasLegend = False
End Sub

See this page for more about charts and VBA:

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

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services - Tutorials and Custom Solutions - 
http://PeltierTech.com/
2006 Excel User Conference, 19-21 April, Atlantic City, NJ
http://peltiertech.com/Excel/ExcelUserConf06.html
_______


"aj" <avram.y.lehrhaupt@lmco.com> wrote in message 
news:1142979318.670046.102690@z34g2000cwc.googlegroups.com...
>I have a user form that inputs data onto a spreadsheet. I have a
> command button that runs a macro that activates the sheet, selects the
> data, and creates the XY Scatter chart. My Problem is that I don't know
> how to set a loop to set each series' properties . (The number of
> series changes every time) Bellow is an example where I manually set
> the properties for three of the series. Any Ideas on how to create a
> loop to set all.
>
> Range("A:A,C:C,D:D").Select
>    Range("D1").Activate
>    Charts.Add
>    ActiveChart.ChartType = xlXYScatter
>    ActiveChart.SetSourceData
> Source:=Sheets("Sheet1").Range("A1:A15,C1:D15"), _
>        PlotBy:=xlRows
>    ActiveChart.SeriesCollection(1).XValues = "=Sheet1!R2C4"
>    ActiveChart.SeriesCollection(1).Values = "=Sheet1!R2C3"
>    ActiveChart.SeriesCollection(1).name = "=Sheet1!R2C1"
>    ActiveChart.SeriesCollection(2).XValues = "=Sheet1!R3C4"
>    ActiveChart.SeriesCollection(2).Values = "=Sheet1!R3C3"
>    ActiveChart.SeriesCollection(2).name = "=Sheet1!R3C1"
>    ActiveChart.SeriesCollection(3).XValues = "=Sheet1!R4C4"
>    ActiveChart.SeriesCollection(3).Values = "=Sheet1!R4C3"
>    ActiveChart.SeriesCollection(3).name = "=Sheet1!R4C1"
>    ActiveChart.Location Where:=xlLocationAsNewSheet, name:="xyCart"
>    With ActiveChart
>        .HasTitle = True
>        .ChartTitle.Characters.Text = "risk"
>        .Axes(xlCategory, xlPrimary).HasTitle = True
>        .Axes(xlCategory, xlPrimary).AxisTitle.Characters.Text =
> "Impact"
>        .Axes(xlValue, xlPrimary).HasTitle = True
>        .Axes(xlValue, xlPrimary).AxisTitle.Characters.Text =
> "Probability"
>    End With
>    With ActiveChart
>        .HasAxis(xlCategory, xlPrimary) = False
>        .HasAxis(xlValue, xlPrimary) = False
>    End With
>    ActiveChart.Axes(xlCategory, xlPrimary).CategoryType = xlAutomatic
>    With ActiveChart.Axes(xlCategory)
>        .HasMajorGridlines = True
>        .HasMinorGridlines = False
>    End With
>    With ActiveChart.Axes(xlValue)
>        .HasMajorGridlines = True
>        .HasMinorGridlines = False
>    End With
>    ActiveChart.HasLegend = False
> End Sub
> 


0
jonxlmvpNO (4558)
3/21/2006 11:30:35 PM
Thanks alot. This really helps.

0
3/22/2006 12:37:05 PM
Thanks again. The stuff above really helped. I am having 2 more issues.
1. How do i set the chart location to create a new sheet called
"RiskMatrix" the first time the create chart button is pressed and then
have it replace the old "RiskMatrix" chart everytime it is pressed
again. 2. I want to format the gridlines but I get an error claiming it
can't change the MinimumScale.

Here is what I added to your code
With Cht.Axes(xlCategory)
    .HasMajorGridlines = True
    .HasMinorGridlines = False
 '    This is what I addedd
    .MinimumScale = 0
    .MaximumScale = 5
    .MinorUnitIsAuto = True
    .MajorUnit = 1.667
    .Crosses = xlAutomatic
    .ReversePlotOrder = False
    .ScaleType = xlLinear
    .DisplayUnit = xlNone
End With

0
3/22/2006 2:14:35 PM
1. This code should work:

Sub DoTheChart()
  Dim WS As Worksheet
  Dim Cht As Chart
  Dim Rng As Range
  Dim iRow As Long

  ' ignore error if "RiskMatrix" doesn't exist
  On Error Resume Next
  ActiveWorkbook.Charts("RiskMatrix").Delete
  On Error Goto 0

  Set WS = ActiveSheet
  Set Cht = Charts.Add
  Cht.Name = "RiskMatrix"
  Cht.ChartType = xlXYScatter

  Set Rng = WS.Range(WS.Range("A2"), WS.Range("A2").End(xlDown))
  For iRow = 2 To 1 + Rng.Rows.Count
    Cht.SeriesCollection.NewSeries
    With Cht.SeriesCollection(iRow - 1)
      .XValues = "='" & WS.Name & "'!R" & iRow & "C4"
      .Values = "='" & WS.Name & "'!R" & iRow & "C3"
      .Name = "='" & WS.Name & "'!R" & iRow & "C1"
    End With
  Next
  With Cht
    .HasTitle = True
    .ChartTitle.Text = "risk"
    .Axes(xlCategory, xlPrimary).HasTitle = True
    .Axes(xlCategory, xlPrimary).AxisTitle.Text = "Impact"
    .Axes(xlValue, xlPrimary).HasTitle = True
    .Axes(xlValue, xlPrimary).AxisTitle.Text = "Probability"
    .HasAxis(xlCategory, xlPrimary) = False
    .HasAxis(xlValue, xlPrimary) = False
  End With
  With Cht.Axes(xlCategory)
    .HasMajorGridlines = True
    .HasMinorGridlines = False
  End With
  With Cht.Axes(xlValue)
    .HasMajorGridlines = True
    .HasMinorGridlines = False
  End With
  Cht.HasLegend = False
End Sub

2. You can't adjust the gridline parameters. The gridline uses the axis 
parameters, so set these instead, and the gridlines will adjust accordingly.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Peltier Technical Services - Tutorials and Custom Solutions - 
http://PeltierTech.com/
2006 Excel User Conference, 19-21 April, Atlantic City, NJ
http://peltiertech.com/Excel/ExcelUserConf06.html
_______

"aj" <avram.y.lehrhaupt@lmco.com> wrote in message 
news:1143036875.755347.59420@z34g2000cwc.googlegroups.com...
> Thanks again. The stuff above really helped. I am having 2 more issues.
> 1. How do i set the chart location to create a new sheet called
> "RiskMatrix" the first time the create chart button is pressed and then
> have it replace the old "RiskMatrix" chart everytime it is pressed
> again. 2. I want to format the gridlines but I get an error claiming it
> can't change the MinimumScale.
>
> Here is what I added to your code
> With Cht.Axes(xlCategory)
>    .HasMajorGridlines = True
>    .HasMinorGridlines = False
> '    This is what I addedd
>    .MinimumScale = 0
>    .MaximumScale = 5
>    .MinorUnitIsAuto = True
>    .MajorUnit = 1.667
>    .Crosses = xlAutomatic
>    .ReversePlotOrder = False
>    .ScaleType = xlLinear
>    .DisplayUnit = xlNone
> End With
> 


0
jonxlmvpNO (4558)
3/23/2006 2:10:59 AM
Great. This really helps. Thank you!

0
3/23/2006 1:31:47 PM
One more question. How do I put a picture from a worksheet in the same
workbook as the chart I am creating in the background of the chart.

I can do it from a file like this:

ActiveChart.PlotArea.Select
    Selection.Fill.UserPicture PictureFile:="C:\My
Documents\Picture2.jpg"
    Selection.Fill.Visible = True

But how can i grab a picture from a worksheet in the same workbook as
the chart I am creating?

0
3/23/2006 8:38:54 PM
Reply:

Similar Artilces:

How to select series in chart?
I know I asked this question before, but (sigh) I cannot find the answer now, when I need it of course. How can I select a series in an Excel chart (XY Scatter) using the keyboard, not the mouse? The issue is: I have overlapping series, so it is difficult for me to select a series by moving the mouse cursor to a point in one series and right-clicking it, as I normally do. Someone once mentioned a ctrl and/or shift key combination (I think) that would allow me to select each series explicit in round-robin fashion. That is what I am looking for again. More generally, how could I have found...

Problems with creating a newsletter
I chose the form "Newsletter - email". I have created a 3 page newsletter. Now, I have NO IDEA how to send it out as an email. I do not want to send it as an attachment. I cannot figure out which "save as" format or what I need to do so that i can email this newsletter. Is there a website that goes through how to do this? Am I correct when I say that it has to be html in order for me to send it as email? That is not one of the options. Any help you give me would be greatly appreciated. Thank you, Markis www.adreamforabetterworld.com ...

Meeting updates #2
My users cannot update meetings created when they were on the old email server. I have noticed that the old string is still mapped to the meeting. e.g x400;c=us;a= ;p=Org name;o=exchagne;s=Lastname;g=firstname; Take a look at the following article: 275134 XADM: Cannot Reply to Messages That Are Sent from a User Account That http://support.microsoft.com/?id=275134 The same thing applies to meetings. How did you move them and what version(s) of Exchange? Thanks, Richard Roddy Microsoft Exchange Support This posting is provided "AS IS" with no warranties, and confers no ri...

Changing SQL Server for CRM 1.2
As my SQL server is currently on its last breath I am in the process of moving our CRM 1.2 databases to a new dedicated serever. I have detatched the databases from the old server, copied the files to the server and attached them. I have then gone into CRM deployment manager and changed to the SQL server to the new server. That all appears to work fine, no error messages. But when users try to access the CRM system they get an error and the CRM server event log fills with error messages. A few are listed below: dmLog: Failed to execute the SQL batch in the file sqlbatch.sql. MSCRM P...

How do you turn off/on the "1" or "2" or "+" or "-" view hide/unh.
What is or how do you control, turn on/off the small "1" "2" or "+" "-" hide/unhide view buttons right above the "A" cell? Sometimes shows when I hide columns. Hi 'Data - Goup/Outline' -- Regards Frank Kabel Frankfurt, Germany Seth wrote: > What is or how do you control, turn on/off the small "1" "2" or "+" > "-" hide/unhide view buttons right above the "A" cell? Sometimes > shows when I hide columns. You can toggle them to hide or display with <Ctrl> <8> Usi...

chart MAcro to change on activecell
Here is the macro below.. The only problem is that the columns change every month. so range (columns)keeps widening.... I have sorted it by selecting range upto column N. so it is provided for all 12 months. But now the "Grand total" column which is always the last column also gets included..(.which shouldnt be included in the range for the chart) Is there a way to modify this macro ? Sub updatechart1() Dim ThechartObj As ChartObject Dim Thechart As Chart Dim Userrow As Long Dim CatTitles As Range Dim SrcRange As Range Dim SourceData As Range If Sheets("summary").Ch...

Steps to Share Outlook on 2 different drives
This is a problem created by a dual boot of XPPSP2 on one drive C:\ and Vista on another drive E:\ that I use to format for new builds of Vista on the same box. I want to take my Outlook 2003 in box and folders on two different drives on one box and combine them so that all the emails go to one account and all the folders can be shared or used on each drive. I want to do the same with Outlook Express as well, and since this is an *Outlook newsgroup, I'll just take what I learn here and apply it to the ..dbx folder(s) in it. The idea is to receive email on both drives in one in one...

printing 2 charts on single page
Using Excel 2k, Win 2k I was trying to print to line charts on a single page to demonstrate the corelation between the two data sets. I would like to print in portait mode with one chart on top of page and one on bottom. Excel only seems to offer putting chart 2 on a separate page or embedding it in chart one. I am not very familiar with excel charting capabilites can anyone suggest a resorce? Thanks ...

transparent areas in charts?
How do you create transparent areas in imbedded charts? (for Excel 2003). When I click on "Format Chart area", then "Fill effects", there is a place where you can change the transparency settings, but it is faded out and will not work. Any Ideas? You can make most elements totally transparent. Ignore the transparency button, which is only for decoration. Instead, if you set an element's area to none, the element will be transparent. - Jon ------- Jon Peltier, Microsoft Excel MVP Tutorials and Custom Solutions Peltier Technical Services, Inc. - http://PeltierTech....

Multiple stacked bar charts
I have a project where i have to chart the compliance of three groups over a number of months. So for each data set there is a Compliance#1 stacked upon NonCompliance#1, then Compliance#2 stacked upon NonCompliance#2 and finally, you guessed it, Compliance#3 stacked upon NonCompliance#3. When i design a chart in excel it wants to place everything on top of each other producing one column of six not the required three columns of two for each week in the display. Can anyone point me i the right direction for this one?? Hi you can achieve this effect by having two layers in your x axis the at...

Offline folder problems #2
Hi Guys, Basically I installed Outlook 97 on my office PC which is connect to microsoft exchange server. For some reason all of my messages were copied into offline folders, this causes a problem, whenever I open up outlook I get this message. Upload of offline changes could not be completed you do not have sufficient permission to perform this operation on this object. See the folder contact or see your system administrator. I do not administrator access on my user profile, every time I open outlook it resets everything I have changed (view etc) and gives that error message. How ...

Linking a Chart with graphics to ppt
Dear group, when I create a chart with scatters, which carry graphics like Excel-Block-Arrows and link this to Powerpoint, the graphics are shown there in a very low quality with large pixels. Any ideas how to improve this? Thanks in advance, Holger. ...

Chart Legend Color Index Assignment
Looking for VBA code to run on Workbook_Open to ensure a Legend having up to 10 different variables does NOT "automatically" assign to same color to 2 different variables. TIA - Bob Check out the color palette (Tools menu > Options > Color tab). The chart uses the bottom two rows of colors for its data, then when it runs out it cycles through the rest of the palette. If the palette has been customized by someone unfamiliar with this behavior, you may get duplication of colors. - Jon ------- Jon Peltier, Microsoft Excel MVP Peltier Technical Services, Inc. http://PeltierTe...

double clicking and draging a column in a chart to chg data
in Excel 2003, double clicking on a column in a chart and then dragging the column up or down would change the data in a table upon which the chart depended. How does one do this in excel 2007? Tom Hi, That feature has been removed in 2007, there is no way to do it. If this helps, click the Yes button. -- Thanks, Shane Devenshire "Tom of inns" wrote: > in Excel 2003, double clicking on a column in a chart and then dragging the > column up or down would change the data in a table upon which the chart > depended. > > How does one do this in excel 2007? &g...

Help, I cannot Save!
I created a document and locked the worksheet to protect the formulars before creating a template for the document. But now when I open th document and insert a new sheet using the template I created, th document will refuse to save. Once I click on save, office assistant will say "doc not saved". Wha could I have done wrong? PLease help. computerfinema -- computerfinema ----------------------------------------------------------------------- computerfineman's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3716 View this thread: http://www.excelforum.c...

Receiving Transaction Entry #2
I went into Receiving Transaction Entry to record the receipt of an item. The invoiced price did not agree with the purchase order. I had to add Shipping and adjust the provincial tax. I went to the proper screen to over-ride the calculated tax and the system told me that I couldn't do that because I had not filled in all the BOLD, RED areas. At that point I wanted to close down that screen, but the system would not let me do that either. I could minimize the screen and then I could also see that there wasn't any required information that had not be entered. The only way I c...

Opening pub files created with older Publisher versions #2
I have just upgraded to Publisher 2003 from 2000 and am having trouble with pub files sent to me for our chuch newsletter which is using Publisher 97 The text is not wrapping around graphics boxes. Can I fix this? I really don't want to go back to Pub 200 Thank Richard this is caused by Publisher 97 not been printer independent. Even if you went back to Publisher 2000, unless you have the identical font versions and printer driver you would have issues with formatting. It sounds like the person sending you the file has a garbage HP inkjet printer. Get them to install the HP5P laser p...

Help Needed in query
hello, everyone Help needed in query i have a table which have three field tabId tabPrtId tabSlab 1 11 50 2 11 100 3 11 150 4 11 200 tabId Is table id it is key also tabPrtId Is Party id in table tabSlab Is slab value now i want result like tabPrtId slabFrom slabTo 11 50 100 11 100 150 11 150 200 means for a particular party id i want to create slabs range -- fro...

Associating Multiple Existing Contacts to an Account, Until CRM 2.x
I have racked my pea-sized brain for endless days for a way to associate multiple existing contacts (or accounts) to an account. My client has accounts that have many contacts (or accounts) involved at different stages of acquiring a new account. The logical method would be to add a custom attribute with lookup functionality into the existing CRM contact or account objects but this is not possible with CRM 1.x. The resulting UI would allow an end user to associate different contacts (or accounts) to an account. Example: Account: ABC - AccountPhysician: (existing account or con...

Help Required
Hi, Whenever I open Outlook 2003, I am getting a dialog box which displays the following message: Microsoft Office Outlook has encountered a problem and needs to close. We are sorry for the inconvenience When I click Debug it displays a message box with the following error message "The instruction at "0x3007e993" referenced memory at "0x0000000:. The memory could not be read" When I click No it Visual Studio JIT debugger pops up. I uninstalled and installed several times but still the problem persists. Is there any regsitry entry that I've to modify/delete? ...

VCard issue #2
This is a weird problem, but when I send a vcard to someone, it shows up in my sent items as a vcf file, and has a vcard icon on it, but when the recipient gets the VCard, it shows up as msg file, with an envelope icon as the attachment. When I open it, nothing is there - it's empty. I can't find anything regarding this problem on google or MS's website. Anybody have any ideas? Is it a problem with Outlook? Do I need to do a detect and repair, a reinstallation? Thanks for your help! Does the same happen when you send a message to yourself? Is he/she able to see it w...

Some Excel formatting functions taking a long time to work #2
Excel 2000 SP3 When I use some formatting functions for the first time in a session, such as bold, increasing font size etc, it takes up to 30 seconds to work. Meantime Excel is locked up until it completes that formatting call. I suspect faulty DLL? Has anyone experienced this? How to fix (other than a complete re- install) ? Any advice appreciated. Piri On Nov 5, 8:39=A0am, Piri <wiremu.pare...@hotmail.com> wrote: > Excel 2000 SP3 > When I use some formatting functions for the first time in a > session, such as bold, increasing font size etc, it takes =A0up to 30 > secon...

Need HELP! for Linking data
Could someone please direct me to where I can learn how to link date in a work book. i.e., I have individual pages for each subject but I need the data that is entered in these individual pages to transfer to the Master page without having to manually in put it.........TNX Bubey, There are not too many bits about linking worksheets or workbooks that I can find. But have a look at the links below, in case they give you the information you need. I think it is frustratingly one of those things which is very easy when you know how, or if you can get someone to actually show you, but if you hav...

Macro Help 11-24-09
I have one workbook of data (1 tab) that has data for 20 different Sales Reps (different names). I need to copy all data for "Rep A" into a separate worksheet, and same for "Rep B" and so on. At the end I would have 1 tab for all data and 20 tabs with the data for each rep. Basically, I need to copy and paste each rep data into a new worksheet within the same workbook but didn't want to do it manually. I hope this makes sense. See Ron de Bruin's site for code. http://www.rondebruin.nl/copy5.htm Also check out his easyfilter add-in. http://www.ro...

TYPING KARAOKE PGS NEED HELP
i am trying to figure out how to type continuous pages for a karaoke catalog 3 headings song title artist disk# when i check print preview it only shows me one page i am new at this typing one handed due to a stroke but i need to also be able to add new songs and then sort them alpa then need to redo by artist the song title then disk if any one can help it would be most appreciated there is approximately 192 pgs ea book thank you so very much patti In Print preview press PgDn. Does this give he next pages? Another issue might be print area. Go to File-Print Area-Clear Print A...