logo
search
VBA & Macro Problems

Fix VBA Photo Misalignment and Slow Excel Workbooks with Many Images

Maira MehtabMaira Mehtab Sep 20, 2026 868 views

Question details

The user needs to resolve an issue where photos inserted via a VBA macro become misaligned over multiple rows, and the workbook suffers from severe performance drops when deleting rows with thousands of images.

Product
Microsoft Excel
Device & OS
not provided
Scenario
Running a VBA macro to automatically insert and manage over 2,000 photos next to SKUs within a single workbook.
Observed behavior
Images gradually lose their alignment with the target cells as more rows are populated, and the workbook becomes extremely slow or freezes when attempting to delete rows.
Before you start

Ensure you save a backup of your workbook with the .xlsm extension before modifying your VBA code, and test the updated macro on a smaller range of rows first.

Solution 1Recommended

Adjust Image Placement and Dimensions via VBA Code

Set each inserted image's position and size relative to its specific target cell and apply the xlMoveAndSize placement property to ensure perfect alignment and dynamic scaling.

By default, images inserted via VBA may float independently of the cells, causing cumulative misalignment when multiple rows are populated or resized. Furthermore, thousands of floating objects can cause extreme performance issues during row deletions.

Setting the Placement property to xlMoveAndSize binds the image to the cell's geometry. This prevents shifting and helps Excel optimize the recalculation of object rendering during row modifications.

1
Access the VBA Editor

Press ALT + F11 to open the Visual Basic Editor and locate the module containing your image insertion macro.

2
Define the Target Cell

In your image insertion loop, ensure you have defined a Range object for the target cell where the specific SKU photo will be placed (e.g., Set TargetCell = Cells(i, 2)).

3
Match Image Position to the Cell

Set the image's Top property to TargetCell.Top and the Left property to TargetCell.Left.

4
Match Image Size to the Cell

Adjust the image's Width and Height properties to match TargetCell.Width and TargetCell.Height.

5
Apply xlMoveAndSize Placement

Apply the setting Placement = xlMoveAndSize to your inserted Picture object so it strictly moves and resizes alongside the target cell.

Performance Tip: Binding images directly to cells using xlMoveAndSize significantly reduces the software's calculation overhead, preventing the workbook from lagging when deleting rows.
Fast & Compatible VBA Support

Effortlessly Manage VBA Macros and Large Workbooks in WPS Office

WPS Spreadsheet offers highly compatible VBA and Macro support, allowing you to run your automated image-insertion scripts smoothly. Its optimized rendering engine is built to handle heavy graphic content and thousands of images without performance drops.

  1. 1. Open Your Workbook: Download and install WPS Office, then open your .xlsm file in WPS Spreadsheet.
  2. 2. Access Macro Tools: Navigate to the Developer tab and click on the 'Visual Basic' icon to access your existing VBA code.
  3. 3. Verify Picture Placement Settings: Check your macro to ensure the Placement = xlMoveAndSize property is applied to inserted images.
  4. 4. Run and Automate: Execute the macro to automatically populate your SKUs and photos, experiencing much faster rendering and row management.
Fully compatible with Microsoft Excel .xlsm formats and VBA scriptsOptimized rendering engine for workbooks containing thousands of imagesFamiliar user interface and dedicated macro editor for quick code adjustmentsLightweight installation and resource-efficient performance
QA img-10

Frequently Asked Questions

Why does my workbook freeze when I delete rows with lots of images?

When rows are deleted, the software attempts to recalculate the positions of all floating objects on the sheet. With thousands of images not explicitly bound to cells (lacking the xlMoveAndSize property), this causes massive memory overhead and severe slowdowns.

What is the exact VBA property to make pictures move with cells?

The exact property is Placement = xlMoveAndSize (which corresponds to the numerical value 1). You must apply this property to the Shape or Picture object directly after it is inserted into the worksheet.

Can I lock the aspect ratio of the photos when resizing them to fit the target cell?

Yes, before configuring the Height and Width properties to match the target cell, you can set the ShapeRange.LockAspectRatio = msoTrue property to prevent the imported images from distorting or stretching.