Use Excel VBA to Find and Copy a Matching Image
Question details
Find a worksheet picture by a name entered in a cell and copy it for manual pasting.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- The user maintains a picture bank and wants to choose the paste destination after finding an image.
- Observed behavior
- A matching picture is copied to the clipboard without specifying a destination.
Use a desktop version of Excel that supports VBA, and save the workbook as an Excel Macro-Enabled Workbook (.xlsm). Make sure the pictures are on the worksheet you will search and enable macros only if you trust the workbook.
Copy a picture by matching its Excel shape name
Use a macro to search the active worksheet for a shape whose name matches the value in C2, then copy it to the clipboard.
The macro compares the search text with Shape.Name, not with text in a cell next to the picture. It searches only the active worksheet and ignores differences in letter case.
On the worksheet, open Home > Find & Select > Selection Pane. Rename each picture with a unique name that matches its corresponding text in column A.
Type the picture's shape name in cell C2 on the same worksheet. Change the C2 reference in the macro if you prefer a different search cell.
Press Alt+F11 to open the VBA editor, select Insert > Module, and paste this code: Sub CopyMatchingImage() Dim ws As Worksheet Dim shp As Shape Dim searchName As String Set ws = ActiveSheet searchName = Trim(CStr(ws.Range("C2").Value)) If searchName = "" Then MsgBox "Enter a picture name in C2." Exit Sub End If For Each shp In ws.Shapes If StrComp(shp.Name, searchName, vbTextCompare) = 0 Then shp.Copy MsgBox "Matching shape copied. Paste it where you want." Exit Sub End If Next shp MsgBox "No matching shape was found on the active worksheet." End Sub
Return to the picture worksheet, press Alt+F8, select CopyMatchingImage, and click Run. After the confirmation appears, choose a destination and paste with Ctrl+V.

Manage spreadsheet pictures with WPS Office
WPS Office is a free, lightweight alternative with a familiar spreadsheet interface and Microsoft Office format support for an easier move between office suites. VBA support varies by WPS version and configuration, so check macro compatibility before relying on the Excel code above.

Frequently Asked Questions
Do I need to specify where the picture will be pasted?
No. The macro uses Shape.Copy to place the matching shape on the clipboard. Choose a destination afterward and paste it manually.
Why does the macro say no matching shape was found?
Check that the correct worksheet is active, then open Home > Find & Select > Selection Pane and compare the picture's shape name with the value in C2.
Can I use a different cell for the search name?
Yes. In the VBA editor, replace ws.Range("C2") with the cell reference you want to use, and enter the shape name in that cell.
Why should I save the workbook as an XLSM file?
The Excel Macro-Enabled Workbook format retains VBA code. Use File > Save As and select Excel Macro-Enabled Workbook (*.xlsm).




