Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Excel Chart

Status
Not open for further replies.

William Heath

Electrical
Apr 23, 2022
4
I have a chaert that is automatically produced by selecting a cell. It has worked for a year but now has failed
 
Replies continue below

Recommended for you

I used the folowing code:


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'simple example of
' dynamically positioning chart and
' assigning values to a single series chart
'you must have a defined range of series names
' and a defined range for the columns containing the Values
'NOTE: Use the Watch Window or Object Browser to discover Object Properties

Dim iColCount As Integer

With Target.Parent.ChartObjects(1) 'the Target's Parent is the Worksheet
If Not Intersect(Target, [seriesnames]) Is Nothing Then 'only selection in the range
If Target.Count = 1 Then 'only if ONE cell selected
.Visible = True

With .Chart.ChartArea 'position chart
.Top = Target.Top + 30
.Left = Target.Left + Target.Width
End With

With .Chart.SeriesCollection(1) 'assign SeriesCol properties
iColCount = Target.Parent.UsedRange.Columns.Count
.Values = Intersect(Target.EntireRow, Range(Cells(1, 2), Cells(1, iColCount)).EntireColumn)
.Name = Target.Value
End With
End If
Else 'chart not visible
.Visible = False
End If
End With
End Sub
 
Somehow, your procedure that I sent you went from 44 lines to 31?

And you failed to upload your workbook, both here and at Tek-Tips.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
bill,

I used my copy of your workbook from 27 Dec 21 19:15.

But if I paste in your code, I get a strange data shift.

Your code modification does not look at min and max values: mine does.

My code, which works perfectly on this workbook, changes the chart y-axis min & max to display the discrete y-values.

So why not tell us what you changed and why.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Hey, Bill, did you get this sorted out?

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor