What is the advantage of creating this Class.

W

WhytheQ

I wanted to create a Class, which I could reuse, to make it easy to
update the range used by charts.
So I've created a Class called "clUpdateGraph" and updated my normal
module code to use this class to update some graphs. It works. It
doesn't seem to have added any great advantage to just using 'normal'
code in a general module.

If anyone has the time could they try this Class and Source code and
tell me what I'm missing; I'm sure this would have been a good
situation to use a Class module: either it wasn't a good situation, or
my use of the class is wrong!

Any help greatly appreciated
JasonQ


'>>>>>>>>>>>>Class Module "clUpdateGraph":
Private GS As Worksheet 'graph sheet name
Private DS As Worksheet 'data sheet name
Private GN As String 'graph name
Private DA As String 'data address


'######################
'read/write string property returning sheet that graph is located in
'######################
Public Property Let GraphSheet(sGSheet As String)
Set GS = ActiveWorkbook.Sheets(sGSheet)
End Property
Public Property Get GraphSheet() As String
GraphSheet = GS.Name
End Property
'
'
'
'######################
'read/write string property returning sheet that data is located in
'######################
Public Property Let DataSheet(sDSheet As String)
Set DS = ActiveWorkbook.Sheets(sDSheet)
End Property
Public Property Get DataSheet() As String
DataSheet = DS.Name
End Property
'
'
'
'######################
'read/write string property returning name of the chart
'######################
Public Property Let GraphName(sGName As String)
GN = sGName
End Property
Public Property Get GraphName() As String
GraphName = GN
End Property
'
'
'
'######################
'read/write string property returning new address for the graph
sourcedata
'######################
Public Property Let NewDataAddress(sAddress As String)
DA = sAddress
End Property
Public Property Get NewDataAddress() As String
NewDataAddress = DA
End Property
'
'
'
'######################
'method that resets data area
'######################
Public Function UpdateGraphRange(GraphName As String) As Boolean

UpdateGraphRange = False
On Error GoTo ErrorOccured
With GS
.ChartObjects(GraphName).Chart.SetSourceData GS.Range(DA)
UpdateGraphRange = True
End With
Exit Function
ErrorOccured:
Err.Raise vbObjectError + 700001, "", "Possibly some of the
properties are not set"

End Function



'>>>>>>>>>>>>in a normal Module:
Sub UpdateGraphRanges()

Dim x As Integer
x = ThisWorkbook.Sheets("Charts").Range("Ac3")

Set myclUpdateGraph = New ClUpdateGraph
With myclUpdateGraph

.GraphSheet = "Charts"
.DataSheet = "Charts"

.NewDataAddress = "AD4:AI" & x
.UpdateGraphRange "Chart 1"

.NewDataAddress = "AG4:AI" & x
.UpdateGraphRange "Chart 2"

.NewDataAddress = "AG4:AG" & x & ",AI4:AI" & x
.UpdateGraphRange "Chart 4"

End With
Set myclUpdateGraph = Nothing

End Sub
 
J

Jon Peltier

In general this wouldn't necessarily be a bad thing. However, in this
specific case, I can't tell what you've done besides design a parallel
feature that does what SetSourceData does. In fact, I was thinking this
before I saw SetSourceData in the UpdateGraphRange method.

- Jon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top