PieChart sizing question

LNG2013

Active Member
Joined
May 23, 2011
Messages
466
Hello,

I was trying to resize my pie chart using VBA instead I shrunk it.

I basically used my current code for creating the pie charts. I then used my handy dandy macro recorder and then recorded an increase in the size of the chart.

My code is below, not sure what I did wrong, it is also left justifying eveything including the legend.


Code:
Sub CreatePieChart()
Dim X, Y As Long
Dim DataArray(2, 4) As Variant
Dim WSheet As Worksheet
Dim sShtName As String
        Dim RngToCover As Range
         Dim ChtOb As ChartObject

Application.ScreenUpdating = False

For Each WSheet In Worksheets
    Sheets(WSheet.Name).Select
    sShtName = ActiveSheet.Name
 
    If Cells(1, 11).Value = "Objective" Then    'you could add other tests here to make sure you only put charts on the sheets you want.
     
        X = 2
        Y = 7
        For Z = 1 To 4
            DataArray(1, Z) = Cells(X, Y + Z - 1).Value
        Next
        X = 3
        Do While True
            If Cells(X, 1).Value = "Total" Then
                Exit Do
            End If
            X = X + 1
        Loop
        Range("G2:J2,G" & X & ":J" & X).Select
                Charts.Add
                
'~~~ The next line indicates where the chart will be placed
        ActiveChart.Location Where:=xlLocationAsObject, Name:=sShtName
        ActiveChart.ChartType = xlPie
      
'~~~ 1.) This part of the code modifies the size and positioning of the Pie Chart
      
        Set RngToCover = ActiveSheet.Range("J" & X & ":M" & X)
         Set ChtOb = ActiveChart.Parent
            ChtOb.Height = 200
            ChtOb.Width = 225
         ChtOb.Top = RngToCover.Top + 120     ' reposition for Piechart from top
         ChtOb.Left = RngToCover.Left + 30    ' reposition
        ActiveChart.ChartArea.AutoScaleFont = False
        
         
[COLOR=red]  '~~~ Test to attempt to resize PieChart (this currently makes the chart smaller) not sure why?
    With ActiveChart.PlotArea
        .Top = 19
        .Width = 140
        .Height = 139
        .Left = 36
        .Top = 25
    End With
[/COLOR]        
        
'~~~ 2.) This part of the area modifies the area around the Pie, removing the border and shading.
    With ActiveChart.PlotArea.Border
        .Weight = xlHairline
        .LineStyle = xlNone
    End With
    With ActiveChart.PlotArea.Interior
        .ColorIndex = xlNone
    End With
 
'~~~ 3.) This section modifies the legend of the Chart
    With ActiveChart
        .Legend.LegendEntries(1).LegendKey.Interior.ColorIndex = 3
        .Legend.LegendEntries(1).LegendKey.Interior.Pattern = xlSolid
        .Legend.LegendEntries(2).LegendKey.Interior.ColorIndex = 44
        .Legend.LegendEntries(2).LegendKey.Interior.Pattern = xlSolid
        .Legend.LegendEntries(3).LegendKey.Interior.ColorIndex = 41
        .Legend.LegendEntries(3).LegendKey.Interior.Pattern = xlSolid
        .Legend.LegendEntries(4).LegendKey.Interior.ColorIndex = 4
        .Legend.LegendEntries(4).LegendKey.Interior.Pattern = xlSolid
        .Legend.Position = xlLegendPositionBottom
        .Legend.Fill.TwoColorGradient Style:=msoGradientVertical, Variant:=1
        .Legend.Fill.Visible = True
        .Legend.Fill.ForeColor.SchemeColor = 37
        .Legend.Fill.BackColor.SchemeColor = 2
        .Legend.Border.Weight = xlHairline
        .Legend.Border.LineStyle = xlNone
    End With
    With ActiveChart.Legend.Font
        .Name = "Arial Rounded MT Bold"
        .FontStyle = "Regular"
        .Size = 12
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
        .Background = xlAutomatic
    End With
    
   '~~~ This section add the title to the chart.
    With ActiveChart
        .HasTitle = True
        .ChartTitle.Characters.Text = "Prompts"
    End With
        With ActiveChart.ChartTitle.Font
        .Name = "Arial Rounded MT Bold"
        .FontStyle = "Regular"
        .Size = 14
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
        .Background = xlAutomatic
    End With
    With ActiveChart.SeriesCollection(1)
        .Explosion = 5
    End With
    
    
   
      
        Range("M33").Select
    End If
Next
 
End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Forum statistics

Threads
1,225,203
Messages
6,183,550
Members
453,168
Latest member
Luggsy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top