-
Feb 23rd, 2018, 12:22 PM
#1
Thread Starter
New Member
VBA Crashes with basic macro
Hi,
New to VBA so forgive the ignorance...I have the attached that is supposed to be producing two charts from a number of named ranges. I've commented off chart two so as to isolate the first chart. Both of these charts worked this morning so I'm not sure what happened. Can someone please see the attached and advise on what might be the issue?
Thanks!
Code:
Sub Relative_Calculation()
Dim BRValue As Name
Dim BRMomentum As Name
Dim BRQuality As Name
Dim BRYield As Name
Dim PRValue As Name
Dim PRMomentum As Name
Dim PRQuality As Name
Dim PRYield As Name
ActiveWorkbook.Names.Add Name:="BRValue", RefersTo:="=Test!$D$13:$O$13-Test!$R$13"
ActiveWorkbook.Names.Add Name:="BRMomentum", RefersTo:="=Test!$D$14:$O$14-Test!$R$14"
ActiveWorkbook.Names.Add Name:="BRQuality", RefersTo:="=Test!$D$15:$O$15-Test!$R$15"
ActiveWorkbook.Names.Add Name:="BRYield", RefersTo:="=Test!$D$16:$O$16-Test!$R$16"
ActiveWorkbook.Names.Add Name:="PRValue", RefersTo:="=Test!$D$13:$O$13-Test!$S$13"
ActiveWorkbook.Names.Add Name:="PRMomentum", RefersTo:="=Test!$D$14:$O$14-Test!$S$14"
ActiveWorkbook.Names.Add Name:="PRQuality", RefersTo:="=Test!$D$15:$O$15-Test!$S$15"
ActiveWorkbook.Names.Add Name:="PRYield", RefersTo:="=Test!$D$16:$O$16-Test!$S$16"
'Defining Chart Objects for three charts (IR/SR)
Set IR = ActiveSheet.ChartObjects.Add(Left:=300, Width:=300, Top:=10, Height:=300)
'Set PortfolioRelative = ActiveSheet.ChartObjects.Add(Left:=900, Width:=300, Top:=10, Height:=300)
'Defining positioning of SR/IR charts
With IR
.Left = 50
.Width = 600
.Top = 10
.Height = 350
End With
With SR
.Left = 300
.Width = 600
.Top = 10
.Height = 350
End With
IR.Select
With ActiveChart
.HasTitle = True
.ChartTitle.Text = "Benchmark Relative Factor Exposures Across Frontier"
'Plot Benchmark Relative Value
.ChartType = xlLine
.SeriesCollection.NewSeries
.SeriesCollection(1).XValues = "=Test!D1:O1"
.SeriesCollection(1).Values = "=Test!BRValue"
.SeriesCollection(1).Name = "=Test!A13"
'Plot Benchmark Relative Momentum
.SeriesCollection.NewSeries
.SeriesCollection(2).XValues = "=Test!D1:O1"
.SeriesCollection(2).Values = "=Test!BRMomentum"
.SeriesCollection(2).Name = "=Test!A14"
'Plot Benchmark Relative Quality
.SeriesCollection.NewSeries
.SeriesCollection(3).XValues = "=Test!D1:O1"
.SeriesCollection(3).Values = "=Test!BRQuality"
.SeriesCollection(3).Name = "=Test!A15"
'Plot Benchmark Relative Yield
.SeriesCollection.NewSeries
.SeriesCollection(4).XValues = "=Test!D1:O1"
.SeriesCollection(4).Values = "=Test!BRYield"
.SeriesCollection(4).Name = "=Test!A16"
End With
'PortfolioRelative.Select
'With ActiveChart
'.HasTitle = True
'.ChartTitle.Text = "Current Portfolio Relative Factor Exposures Across Frontier"
'Plot Current Portfolio Relative Value
'.ChartType = xlLine
'.SeriesCollection.NewSeries
'.SeriesCollection(1).XValues = "=Test!D1:O1"
'.SeriesCollection(1).Values = "=Test!PortfolioRelativeValue"
'.SeriesCollection(1).Name = "=Test!A13"
'Plot Current Portfolio Momentum
'.SeriesCollection.NewSeries
'.SeriesCollection(2).XValues = "=Test!D1:O1"
'.SeriesCollection(2).Values = "=Test!PortfolioRelativeMomentum"
'.SeriesCollection(2).Name = "=Test!A14"
'Plot Current Portfolio Quality
'.SeriesCollection.NewSeries
'.SeriesCollection(3).XValues = "=Test!D1:O1"
'.SeriesCollection(3).Values = "=Test!PortfolioRelativeQuality"
'.SeriesCollection(3).Name = "=Test!A15"
'Plot Current Portfolio Yield
'.SeriesCollection.NewSeries
'.SeriesCollection(4).XValues = "=Test!D1:O1"
'.SeriesCollection(4).Values = "=Test!PortfolioRelativeYield"
'.SeriesCollection(4).Name = "=Test!A16"
'End With
End Sub
Last edited by si_the_geek; Feb 24th, 2018 at 07:13 AM.
Reason: fixed Code tags
-
Feb 23rd, 2018, 12:23 PM
#2
Thread Starter
New Member
Re: VBA Crashes with basic macro
also, I was attempting to add code tags to the above. How do I do that?
-
Feb 23rd, 2018, 06:36 PM
#3
Re: VBA Crashes with basic macro
If you can still edit your post, you can place the tags like this, substituting square brackets for the parentheses:
(code)
' code goes here
(/code)
Or click the "#" symbol above the text editing box.
-
Feb 24th, 2018, 07:18 AM
#4
Re: VBA Crashes with basic macro
Welcome to VBForums
Thread moved from the 'VB.Net' forum to the 'Office Development/VBA' forum.
I've fixed the code tags... as jdc2000 said, they should be like this: [code] code here [/code]
-
Feb 24th, 2018, 06:32 PM
#5
Re: VBA Crashes with basic macro
VBA Crashes with basic macro
does this mean that the macro stops with an error, or excel completely closes or stops and has to be closed?
have you restarted excel? windows?, has your windows version done an update?
if you get an error, what is the error number and message?
if the macro stops with an error and you get a stop /debug message, what line is the macro at when selecting debug?
if excel totally stops you will need to step through the macro one line at a time to find which line causes the crash
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 25th, 2018, 03:47 AM
#6
Re: VBA Crashes with basic macro
Maybe good if you attach your Excel file for test
-
Feb 26th, 2018, 01:35 PM
#7
Re: VBA Crashes with basic macro
You said it was working this morning..?
What did you change? Coding? Location of xls? Changed a named range? Or deleted one?
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|