Solved

VBA Excel to set chart back ground to no fill

Posted on 2011-09-05
2
3,092 Views
Last Modified: 2012-06-21
Hi Experts

I have some code that sets the background of an active chart so that the gridlines can not be seen, code works fine, but the problem is that the background appears to be set by the shape control not the char control t, so if two charts are named the same then the back ground will only set on one chart, is there a better way to set the active shape as the current chart selected regardless of name?

ps. I know I can loop throught the number of shapes and set the shape based upon the chart name.

 
ActiveChart.PlotArea.Format.Fill.Visible = msoFalse
 ActiveSheet.Shapes(LTrim(Replace(ActiveChart.Name, ActiveSheet.Name, ""))).Fill.Visible = _
 msoFalse

Open in new window

0
Comment
Question by:MrDavidThorn
[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
  • 2
2 Comments
 
LVL 81

Expert Comment

by:byundt
ID: 36484931
You might try looping through the ChartObjects collection to avoid conflicts with duplicate names. The code below sets the background color to white.

Sub ChartBackgrounds()
Dim co As ChartObject
For Each co In ActiveSheet.ChartObjects
    co.Chart.ChartArea.Format.Fill.ForeColor.RGB = RGB(255, 255, 255)
Next
End Sub

Open in new window

0
 
LVL 81

Accepted Solution

by:
byundt earned 500 total points
ID: 36484935
This tweak to the original code sets the visibility of the Fill property to False for both the ChartArea and PlotArea.

Sub ChartBackgrounds()
Dim co As ChartObject
For Each co In ActiveSheet.ChartObjects
    co.Chart.ChartArea.Format.Fill.Visible = msoFalse
    co.Chart.PlotArea.Format.Fill.Visible = msoFalse
Next
End Sub

Open in new window

0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
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…

690 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