VBA Code to Resize All Charts in a Worksheet in Excel

VBA code that you can use to resize all charts in a worksheet in Excel.

VBA Code:

Sub ResizeAllCharts()
    Dim ws As Worksheet
    Dim cht As ChartObject
    
    ' Set the worksheet you want to resize charts in
    Set ws = ThisWorkbook.Worksheets("Sheet1") ' Change "Sheet1" to the desired worksheet name
    
    ' Loop through each chart in the worksheet
    For Each cht In ws.ChartObjects
        ' Resize the chart to fit within the worksheet's range
        With cht
            .Width = ws.UsedRange.Width ' Adjust width to fit within the used range of the worksheet
            .Height = ws.UsedRange.Height ' Adjust height to fit within the used range of the worksheet
        End With
    Next cht
    
    ' Inform the user that the charts have been resized
    MsgBox "All charts in the worksheet have been resized!"
End Sub


Check All VBA Codes

Join Our Telegram Group techguruplus telegram group Join Our WhatsApp Group techguruplus whatsapp group
Nazim Khan - Author Image

Nazim Khan (Author)

Nazim Khan is an expert in Microsoft Excel. He teaches people how to use it better. He has been doing this for more than ten years. He has a website and a YouTube channel called "Business Excel." He shares useful tips from his own experiences to help others improve their Excel skills and careers.

Leave a Comment