|
-
Aug 18th, 2012, 05:25 PM
#1
Thread Starter
New Member
Excel Select Chart Index
I have the following code:
Code:
Sub GetTLineEq()
Dim chrtobj As ChartObject
Dim chrt As Chart
Dim srs As Series
Dim tline As trendline
Dim dlbl As DataLabel
Dim str As String
With ActiveSheet
Set chrtobj = ActiveSheet.ChartObjects(1)
Set chrt = chrtobj.Chart
Set srs = chrt.SeriesCollection(1)
Set tline = srs.Trendlines(1)
Set dlbl = tline.DataLabel
str = dlbl.Text
.Range(Selection.Address).Value = str
End With
End Sub
I would like the Macro to work with selected chart instead of ChartObjects(1). I have many charts in the spreadsheet. Many thanks.
-
Aug 19th, 2012, 05:26 AM
#2
Re: Excel Select Chart Index
it is easy enough to do, but have to make sure the chart is selected properly
Code:
if the typename(selection)= "ChartArea" then
set chrtobj = selection
else
msgbox "chart not selected correctly"
end if
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
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
|