?
Solved

VBA color chart bars

Posted on 2016-09-01
12
Medium Priority
?
126 Views
Last Modified: 2016-09-02
Dear All,

First of all I would like to thank you for further comments and reading my question!
I am really Need in your help!

I created a Chart by using Pivot table.The Chart Shows the Name of the products and Revenue for each of this products.

Could you please help me,how can i do in VBA or by another method,I want to choose the one product,press on it,and it will be automatically Shows on the graph by changing Color only of the bar of this specific product ?

for example,all columns are Grey,then i will choose on product,and this product will be automatically Shows by red on the chart

I am really appreciate your help!I am very tried to explain...
0
Comment
Question by:Yana Burmistrova
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
12 Comments
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 41779376
You would have to upload a sample excel file to understand and work on the problem.
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 41779382
BTW Please delete your other question to eliminate any confusion.
0
 

Author Comment

by:Yana Burmistrova
ID: 41779420
Please find attached
VBA.xlsx
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 41779523
Hi,

pls try to dbl-click on the first column
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Set myRng = ActiveSheet.PivotTables(1).RowRange.Resize(ActiveSheet.PivotTables(1).RowRange.Rows.Count - 2).Offset(1)

Set SerCol = ActiveSheet.Shapes(1).Chart.SeriesCollection(1)
ActiveSheet.Shapes(1).Chart.ClearToMatchStyle
If Not Intersect(Target, myRng) Is Nothing Then
    res = 0
    On Error Resume Next ' find corresponding XValue
    res = WorksheetFunction.Match(Cells(Target.Row, 1), SerCol.XValues, 0)
    On Error GoTo 0
    If res <> 0 Then ' if found
        With SerCol.Points(res).Format.Fill
            .Visible = msoTrue
            .ForeColor.RGB = RGB(255, 0, 0)
            .Solid
        End With
    End If

Else
  '  ActiveSheet.Shapes(1).Chart.ClearToMatchStyle
End If
End Sub

Open in new window

Regards
VBAv1.xlsm
0
 

Author Comment

by:Yana Burmistrova
ID: 41779543
Thank you so much for your help!!!!
you are an expert!
 
I am very appreciate your help!

it works!!!
Could you please let me know,is it possible to add also the Name of the product?

For example,when i double clicked on the product,the Color Change and Shows on the graph,is it possible also to add the Name of the choosing product on the upp of the column ?
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 41779637
You mean in the chart?
0
 

Author Comment

by:Yana Burmistrova
ID: 41779674
yes,please.only for choosing product
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 41779754
then try
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

Set myRng = ActiveSheet.PivotTables(1).RowRange.Resize(ActiveSheet.PivotTables(1).RowRange.Rows.Count - 2).Offset(1)

Set SerCol = ActiveSheet.Shapes(1).Chart.SeriesCollection(1)
ActiveSheet.Shapes(1).Chart.ClearToMatchStyle
On Error Resume Next
SerCol.DataLabels.Delete
On Error GoTo 0
If Not Intersect(Target, myRng) Is Nothing Then
    res = 0
    On Error Resume Next ' find corresponding XValue
    res = WorksheetFunction.Match(Cells(Target.Row, 1), SerCol.XValues, 0)
    On Error GoTo 0
    If res <> 0 Then ' if found
        With SerCol.Points(res).Format.Fill
            .Visible = msoTrue
            .ForeColor.RGB = RGB(255, 0, 0)
            .Solid
        End With
        SerCol.Points(res).ApplyDataLabels
        SerCol.Points(res).DataLabel.ShowCategoryName = True
        SerCol.Points(res).DataLabel.ShowValue = False
    End If

Else
  '  ActiveSheet.Shapes(1).Chart.ClearToMatchStyle
End If
End Sub

Open in new window

VBAv2.xlsm
0
 

Author Comment

by:Yana Burmistrova
ID: 41779757
excelent!!!!!

Thank you very much!!!
0
 

Author Comment

by:Yana Burmistrova
ID: 41781133
Dear All,
Could you please help me to do the same ,but with a simple Chart and data in Excel?

how can i do automatically showing the Color and Name of the product,without Pivot table?

I am very appreciate your help!

Thank you very much for your futher answers and comments!!!
Excel-VBA.xlsx
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 41781134
Hi,

Could you open a new question?

Regards
0
 

Author Comment

by:Yana Burmistrova
ID: 41781135
yes sure!
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question