ThisCalculator

Everyday

Excel Shape Size Based on Cell Value?

Updated · Standard formula, shown below

Shape area 15.00 cm²
Diagonal
5.83 cm
Result
Target width
5 cm
You entered
Target height
3 cm
You entered

Excel Shape Size Based on Cell Value?

Yes, you can make an Excel shape’s size automatically depend on a cell value, and the standard way to do it is with a simple VBA macro that runs whenever that cell changes. You enter a number in a cell, and the shape’s width and height update instantly to match a scale you define; this article explains the exact code, how to install it, and the practical limits you should know about.

Formula

If you want to compute the resulting area or diagonal from a shape’s width and height, the formulas are:

  • Area = width × height (both in the same unit, result in square units)
  • Diagonal = √(width² + height²) (from the Pythagorean theorem)

Where width and height are the shape’s dimensions in whatever unit you choose (cm, inches, points). The calculator above works in centimeters; Excel’s internal unit is points (1 cm ≈ 28.35 pt), but the macro examples below use points directly because that’s what Excel’s .Width and .Height properties expect.

Worked Example

Using the defaults from the calculator: width = 5 cm, height = 3 cm.

  1. Area = 5 × 3 = 15 cm²
  2. Diagonal = √(5² + 3²) = √(25 + 9) = √34 ≈ 5.83 cm

The calculator rounds to 2 decimals, so it shows 15.00 cm² and 5.83 cm – exactly what the formula gives.

Why You Might Want This

Manual resizing is fine for a one-off chart, but when you have a dashboard or a report where the shape’s size should reflect a metric (e.g., a square that grows with sales, a circle that represents a percentage, or a rectangle that scales with a budget), doing it by hand every time the data updates is tedious and error-prone. Automating it makes the visual update instantly and consistently.

Common use cases include:

  • Creating a simple bar chart alternative using rectangles
  • Making a bubble chart where the circle size is proportional to a value
  • Building a dynamic infographic or KPI dashboard
  • Scaling a logo or icon to match a numeric rating

How to Make a Shape Resize Based on a Cell Value (VBA)

The core technique uses a worksheet event macro. Here’s a step-by-step guide for Excel 2016 and later (including Microsoft 365):

  1. Press Alt+F11 to open the Visual Basic for Applications (VBA) editor.
  2. In the Project Explorer (left pane), double-click the worksheet that contains the shape and the cell you want to link to (e.g., Sheet1).
  3. Paste the following code into the code window:
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim shp As Shape
    Dim scaleFactor As Double
    
    ' Change "A1" to the cell you are monitoring
    If Not Intersect(Target, Range("A1")) Is Nothing Then
        ' Change "MyShape" to your shape's name
        Set shp = Me.Shapes("MyShape")
        
        ' Scale factor: 1 point per unit of value
        scaleFactor = Target.Value * 1
        
        ' Set new size (width and height in points)
        shp.Width = scaleFactor
        shp.Height = scaleFactor
    End If
End Sub
  1. Close the editor and save the workbook as a Macro-Enabled Workbook (*.xlsm) if you want to keep the macro.
  2. Now, when you change the value in A1, the shape (named “MyShape”) will resize to that many points wide and tall.

To find your shape’s name: click the shape, then look at the Name Box (the dropdown left of the formula bar). You can rename it there.

Choosing the Right Scaling Method

The simple example above sets width and height equal to the cell value in points. That’s often too small (a value of 10 gives a 10‑point square, which is tiny). You’ll typically want a multiplier or a formula. Here are three common approaches:

  • Linear scale: shp.Width = Target.Value * 10 – easy, but can get too large or too small quickly.
  • Proportional to area: If you want the shape’s area to be proportional to the value, set width and height to Sqr(Target.Value) * factor. This makes the visual size (area) match the number.
  • Clamp to a range: Use Application.WorksheetFunction.Min(Max(value, min), max) to prevent the shape from becoming invisible or overflowing the sheet.

For example, if you want a circle to represent a percentage (0‑100), you might set its diameter to Target.Value * 2 points. That gives a 200‑point circle at 100%, which is a reasonable visual.

Common Problems and How to Avoid Them

  • Shape doesn’t resize: Check that the shape name in the code matches exactly (case‑insensitive, but spaces matter). Also ensure the macro is in the correct worksheet module, not a standard module.
  • Macro doesn’t run: Make sure macros are enabled. In Excel, go to File > Options > Trust Center > Trust Center Settings > Macro Settings and choose “Disable VBA macros with notification” or enable all macros (for trusted workbooks).
  • Resizing every cell change: The event fires on any change in the worksheet. If you have multiple linked shapes, you might want to use a specific range check, as above.
  • Shapes jump around: If you also move the shape’s position in the macro, it can be disorienting. Keep resizing separate from positioning.
  • Performance: For very frequent changes (e.g., real‑time data), the macro can slow down. You can disable events temporarily with Application.EnableEvents = False at the start and re‑enable at the end, but be careful to re‑enable it even on error.

Alternatives to VBA

If you prefer not to use VBA (for security or compatibility reasons), there are a few non‑macro options, though they are more limited:

  • Use a chart instead: A bar or bubble chart can be made to resize automatically based on data, and it’s easier to maintain.
  • Conditional formatting with data bars: This works for cells, not shapes, but can visually represent a value without any code.
  • Named formulas with defined names: You can define a name that references a cell, but you still need VBA to apply it to a shape’s size.
  • Power BI or other dashboard tools: If you’re building a complex dashboard, a dedicated tool might be more robust.

For most users, the VBA method is the only direct way to resize a shape from a cell value. If you’re not comfortable with VBA, a chart is usually the better choice.

Frequently Asked Questions

Can I make a shape resize based on a formula result, not just a typed value?

Yes. The Worksheet_Change event only fires when a cell is manually changed. If the cell contains a formula, you should use the Worksheet_Calculate event instead, which fires after any recalculation. The code is similar, but you don’t need the Target check – just read the cell’s value directly.

How do I keep the shape’s aspect ratio fixed when resizing?

Set only one dimension (e.g., width) and set the other to the same value, or use a fixed ratio: shp.Height = shp.Width * 0.5 for a 2:1 ratio. For circles, always set both equal.

Why does my shape disappear when the cell is empty or zero?

If the value is 0, the width becomes 0, which makes the shape invisible. Add a minimum size check: If Target.Value < 1 Then Target.Value = 1 or use Max function in VBA.

Can I link multiple shapes to different cells?

Yes. In the same Worksheet_Change macro, you can add multiple If blocks, each checking a different cell and resizing a different shape. Just make sure each shape name is unique.

Does this work in Excel for Mac?

Yes, VBA is available in Excel for Mac, but the keyboard shortcut to open the editor is Fn+Alt+F11. The code is identical, though some minor UI differences exist.

Is there a way to do this without saving as .xlsm?

No, if you use VBA, the workbook must be saved as a macro‑enabled file (.xlsm) to retain the code. If you don’t want to save as .xlsm, you’d have to use a non‑VBA method, which is limited as described above.

Related

Formula used
in t | Target width | cm | 5 | 0
in h | Target height | cm | 3 | 0
out area | Shape area | cm² | t * h | 2
out diag | Diagonal | cm | sqrt(t^2 + h^2) | 2

Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.