ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How to macro simple graphs (https://www.excelbanter.com/excel-programming/339955-how-macro-simple-graphs.html)

mikerr[_5_]

How to macro simple graphs
 

Hi all, I wanted to thank the Excel community for your earlier efforts
by showing y'all how to macro a graph and save yourselves a number of
of steps.

To put this code into your excel sheet:
1. Start recording a macro. I recommend using control-a for the
hotkey. Stop recording,go into the macro code (tools-macro-macro),
and copy and paste the below code in place of what excel made.
2. In the code below, change "forecastv12" to the name of your current
excel file.

What this code does:
1. Select a range of cells with numbers in them, i.e. cell a1 through
cell a10,
2. Hit the hotkey (again, I recommend ctrl-a as it is easy to do
repeatedly).
3. You will see a simple line graph with a best-fit line complete with
equation.
4. This can be repeated as many times as you want.

If you want to customize this to your own taste and don't know how, try
putting your question here. Maybe someone will help!

Sub MakeNewGraph()
'
' MakeNewGraph Macro
' Macro recorded 8/4/2005 by ...
' Keyboard Shortcut: Ctrl+a
'
Dim sActiveSheet As String
sActiveSheet = Workbooks("Forecastv12.xls").ActiveSheet.Name
' Dim sActiveCol As String
' sActiveCol = ActiveCell.Name

Charts.Add
'Charts.Add.Name = "Column" + sActiveColumn
ActiveChart.Location Whe=xlLocationAsObject, Name:=sActiveSheet
ActiveChart.ChartType = xlLineMarkers
ActiveChart.SeriesCollection(1).Select
ActiveChart.SeriesCollection(1).Trendlines.Add(Typ e:=xlLinear,
Forward:=0, _
Backward:=0, DisplayEquation:=True,
DisplayRSquared:=True).Select
ActiveChart.SeriesCollection(1).Trendlines(1).Data Label.Select
Selection.Left = 142
Selection.Top = 1


End Sub


--
mikerr
------------------------------------------------------------------------
mikerr's Profile: http://www.excelforum.com/member.php...o&userid=25830
View this thread: http://www.excelforum.com/showthread...hreadid=467236



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

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