How to auto change shape size based/dependent on specified cell value in Excel?
If you want to automatically change the shape size based on the value of a specified cell, this article can help you.
Auto change shape size based on specified cell value with VBA code
Auto change shape size based on specified cell value with VBA code
The following VBA code can help you to change a certain shape size based on specified cell value in current worksheet. Please do as follows.
1. Right click the sheet tab with shape you need to change size, and then click View Code from the right-clicking menu.
2. In the Microsoft Visual Basic for Applications window, copy and paste the following VBA code into the Code window.
VBA code: Auto change shape size based on specified cell value in Excel
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
If Target.Row = 2 And Target.Column = 1 Then
Call SizeCircle("Oval 2", Val(Target.Value))
End If
End Sub
Sub SizeCircle(Name As String, Diameter)
Dim xCenterX As Single
Dim xCenterY As Single
Dim xCircle As Shape
Dim xDiameter As Single
On Error GoTo ExitSub
xDiameter = Diameter
If xDiameter > 10 Then xDiameter = 10
If xDiameter < 1 Then xDiameter = 1
Set xCircle = ActiveSheet.Shapes(Name)
With xCircle
xCenterX = .Left + (.Width / 2)
xCenterY = .Top + (.Height / 2)
.Width = Application.CentimetersToPoints(xDiameter)
.Height = Application.CentimetersToPoints(xDiameter)
.Left = xCenterX - (.Width / 2)
.Top = xCenterY - (.Height / 2)
End With
ExitSub:
End Sub
Note: In the code, “Oval 2” is the shape name you will change its size. And Row = 2, Column = 1 means that the size of shape “Oval 2” will be changed with the value in A2. Please change them as you need.
For auto resizing multiple shapes based on different cell values, please apply the below VBA code.
VBA code: Auto resize multiple shapes based on different specified cells' value in Excel
Private Sub Worksheet_Change(ByVal Target As Range)
Dim xAddress As String
On Error Resume Next
If Target.CountLarge = 1 Then
xAddress = Target.Address(0, 0)
If xAddress = "A1" Then
Call SizeCircle("Oval 1", Val(Target.Value))
ElseIf xAddress = "A2" Then
Call SizeCircle("Smiley Face 3", Val(Target.Value))
ElseIf xAddress = "A3" Then
Call SizeCircle("Heart 2", Val(Target.Value))
End If
End If
End Sub
Sub SizeCircle(Name As String, Diameter)
Dim xCenterX As Single
Dim xCenterY As Single
Dim xCircle As Shape
Dim xDiameter As Single
On Error GoTo ExitSub
xDiameter = Diameter
If xDiameter > 10 Then xDiameter = 10
If xDiameter < 1 Then xDiameter = 1
Set xCircle = ActiveSheet.Shapes(Name)
With xCircle
xCenterX = .Left + (.Width / 2)
xCenterY = .Top + (.Height / 2)
.Width = Application.CentimetersToPoints(xDiameter)
.Height = Application.CentimetersToPoints(xDiameter)
.Left = xCenterX - (.Width / 2)
.Top = xCenterY - (.Height / 2)
End With
ExitSub:
End Sub
Notes:
3. Press Alt + Q keys simultaneously to close the Microsoft Visual Basic for Applications window.
From now on, when you change the value in cell A2, the size of shape Oval 2 will be changed automatically. See screenshot:
Or change the values in cell A1, A2 and A3 to resize the corresponding shapes "Oval 1", "Smiley Face 3" and "Heart 3" automatically. See screenshot:
Note: The shape size will no longer change when the cell value is greater than 10.
List and export all shapes in current Excel workbook:
The Export Graphics utility of Kutools for Excel help you quickly list all shapes in current workbook, and you can export them all to a certain folder at once as the below screenshot shwon. Download and try it now! (30-day free trail)
Related articles:
- How to add mouse over tip to a certain shape in Excel?
- How to fill a shape with transparent background color in Excel?
- How to hide or unhide a certain shape based on specified cell value in Excel?
Best Office Productivity Tools
Supercharge Your Spreadsheets: Experience Efficiency Like Never Before with Kutools for Excel
Kutools for Excel boasts over 300 features, ensuring that what you need is just a click away...
Supports Office/Excel 2007-2021 & newer, including 365 | Available in 44 languages | Enjoy a full-featured 30-day free trial.
Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier
- Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
- Open and create multiple documents in new tabs of the same window, rather than in new windows.
- Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!

















