Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Ketan Dave   on Jan 18 In MS Office Category.

  
Question Answered By: Huette Miller   on Jan 18

Since I posted my code and problem
earlier today, I have modified the code (see below). Despite my
modifications, I am still receiving errors.

I have a VBA coding problem  with the Sub below. All lines work fine
until I reach the lines commented with asterisks * * *. Those 7 lines
of Series Collection code are puzzling me. Could you please go over
my code and tell me (show me) what I'm doing wrong ?

Sub ChartTrial()

Dim DataRange As Range
Dim UpperLmtRange As Range
Dim LowerLmtRange As Range
Dim TimeFrame As Range
Dim DataName As String
Dim UpperLmtName As String
Dim LowerLmtName As String
Dim XMax As Long
Dim XMin As Long
Dim XUnit As Long
Dim amtrows As Long

'assign names
DataName = "Region1"
UpperLmtName = "Upper Limit"
LowerLmtName = "Lower Limit"

'determine axis scale limits
XMax = Range("Sheet3!B6").Value
XMin = Range("Sheet3!B7").Value
XUnit = Range("Sheet3!B8").Value

'get count of data rows to plot
amtrows = Range("Sheet5!C4").Value

'set-up ranges to plot
Set TimeRange = Range("Sheet3!C7").Resize(amtrows, 1)
Set DataRange = Range("Sheet3!D7").Resize(amtrows, 1)
Set UpperLmtRange = Range("Sheet3!E7").Resize(amtrows, 1)
Set LowerLmtRange = Range("Sheet3!F7").Resize(amtrows, 1)

ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.ChartArea.Select

'set axis scale values
With ActiveChart.Axes(xlValue)
.MaximumScale = XMax
.MinimumScale = XMin
.MinorUnit = XUnit
End With

'assign data range
ActiveChart.SetSourceData Source:=DataRange, PlotBy:=xlColumns

ActiveChart.SeriesCollection(1).Name = DataName
ActiveChart.SeriesCollection(1).Values = DataRange

'* * *errors occur with the next 7 lines
ActiveChart.SeriesCollection(2).Name = UpperLmtName
ActiveChart.SeriesCollection(2).Values = UpperLmtRange
ActiveChart.SeriesCollection(3).Name = LowerLmtName
ActiveChart.SeriesCollection(3).Values = LowerLmtRange
ActiveChart.SeriesCollection(1).XValues = Range(TimeFrame)
ActiveChart.SeriesCollection(2).XValues = Range(TimeFrame)
ActiveChart.SeriesCollection(3).XValues = Range(TimeFrame)
'* * * errors end here

ActiveWindow.Visible = False

Range("A1").Select

End Sub

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on VBA Help With Chart Object Problem Or get search suggestion and latest updates.


Tagged: