LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 246
Default What is the advantage of creating this Class.

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
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating UDF by Class Module (Leo)? Leo Excel Discussion (Misc queries) 1 December 2nd 08 10:59 AM
creating xy graph charts for algebra class Dave Excel Discussion (Misc queries) 1 January 8th 08 02:01 PM
Creating a collection in a class Memento Excel Programming 3 June 20th 07 10:45 AM
Creating a User Defined Class / Object Andrew Hall NZ Excel Programming 3 December 11th 06 10:27 AM
Class module creating OLEObject Erich Neuwirth Excel Programming 0 August 11th 04 12:43 PM


All times are GMT +1. The time now is 07:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"