Add new series on a graph using a macro

aikue

New Member
Joined
Aug 8, 2014
Messages
10
Hello everyone. I am trying to create a macro. I am very inexperienced and my knowledge of coding is very minimal. I would be very grateful if anyone could help me out. Thank you :)

This is a copy of my table (bold are the rows and coloums). The workbook is called "PSD Graphs". The Sheet is called "Cone Crusher PSD."

I want to enter data on a weekly basis, adding more rows as the year progresses. I want to make a macro so I can select a date and add its row of data onto my graph.

BAEAFAGAHAO
5905031.5250
2363-jul55.97.73.42.10
23711-jul40.28.3110
23824-jul84.920.33.63.10
23930-jul36.813.90.80.60

<tbody>
</tbody>

I tried recording a macro and this is what I get:

Sub Macro11()
'
' Macro11 Macro
'
' Keyboard Shortcut: Ctrl+m
'
ActiveSheet.ChartObjects("Chart 5").Activate
ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(2).Name = "='Cone Crusher PSD'!$B$238"
ActiveChart.SeriesCollection(2).XValues = "={90,50,31.5,25}"
ActiveChart.SeriesCollection(2).Values = "='Cone Crusher PSD'!$AE$238:$AO$238"
End Sub


When I select a date and try to apply my macro, it adds a blank series to my graph.

Thank you again for any help!!
 
This would do it:

Code:
Sub Macro11()
'
' Macro11 Macro
'
' Keyboard Shortcut: Ctrl+m
'
r = ActiveCell.Row
With ActiveSheet.ChartObjects("Chart 5").Chart
n = .SeriesCollection.Count
Set ns = .SeriesCollection.NewSeries
ns.Name = "='Cone Crusher PSD'!$B$" & r
.SeriesCollection(n + 1).XValues = "={90,50,31.5,25}"
.SeriesCollection(n + 1).Values = "='Cone Crusher PSD'!$AE$" & r & ":$AO$" & r
End With
End Sub
Is there any way I can repay you for your help? I appreciate the help tremendously. I really want to learn how to write macros myself. Do you know of any good online lessons or programs?
Don't worry about payment or anything - I'm free for now. ;)

Plus the learning opportunity is kind of a payment in itself - I'd never have came up with that solution if it weren't for this thread, and now I know it for the future.

Anyway, I appreciate your gratitude. :)

As for learning, I'm a great believer in learning by experience. I learned in the following ways:

1) Recording macros and studying the resulting code; learning which parts of it were necessary and which weren't; condensing it; understanding the syntax.

2) Searching/asking for help on this forum.

3) Answering questions on this forum.

4) Being creative/ambitious - I've found that pretty much anything that can be conceived of logically is possible with VBA.

I think it's also really helpful to have things to work on, for example, I worked in Finance and had lots of uses for VBA there, e.g., tasks that would have otherwise been massively repetitive. I feel that that was the main reason I picked up VBA fairly quickly.

Another valuable asset is an already good understanding of worksheet formulas and functions, as these can translate pretty directly into VBA.

Hope this helps,

Chris.
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
It works! :') too beautiful. Thanks again!

I can see Finance being very repetitive and good motivation to learn VBA, lol.

I am still in school, halfway through engineering. I want to learn VBA because it looks pretty nice on a resume (lol) and it will help me out a lot down the road. Thank you for the tips :)!
 
Upvote 0

Forum statistics

Threads
1,216,114
Messages
6,128,910
Members
449,478
Latest member
Davenil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top