Skip to main content

How to replace text with corresponding pictures in Excel?

doc replace text with image 1  2 doc replace text with image 2

Let’s say, I have a list of product names in a worksheet, and there is a folder contains the corresponding pictures of the product names in the computer disk. Now, I need to find and replace the product names with their relative images in Excel without insert them one by one as following screenshots shown. Any there any good and quick solutions to deal with this job in Excel?

Replace text with corresponding pictures with VBA code

Replace text with corresponding pictures with Kutools for Excel


Replace text with corresponding pictures with VBA code

Normally, there is no easy and direct way for us to insert the relative pictures based on the text string in Excel, but, the following VBA code may help you to replace the text with its corresponding picture.

1. Press Alt + F11 to display the Microsoft Visual Basic for Applications window.

2. In the window, click Insert > Module to show a new module window, then copy and paste the following VBA code into the module window.

VBA code: replace text with corresponding pictures

Sub InsertPicture()
'Upadateby Extendoffice
Dim xPath As String
Dim xLastRow As Long
Dim Rng As Range
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
xPath = "C:\Users\dt\Desktop\Fruits\"
If Right(xPath, 1) <> "\" Then xPath = xPath & "\"
xLastRow = Cells(Rows.Count, "A").End(xlUp).Row
For Each Rng In WorkRng
    If Rng.Value <> "" Then
        If Dir(xPath & Rng.Value & ".jpg") <> "" Then
            ActiveSheet.Pictures.Insert(xPath & Rng.Value & ".jpg").Select
            With Selection.ShapeRange
                .LockAspectRatio = msoFalse
                .Left = Rng.Left
                .Top = Rng.Top
                .Width = Rng.Width
                .Height = Rng.Height
            End With
            Rng.ClearContents
        Else
            Rng.Value = "N/A"
        End If
    End If
Next
Application.ScreenUpdating = True
End Sub

3. Then press F5 key to run this code, and select the data range that you want to insert the corresponding pictures in the popped out dialog, see screenshot:

doc replace text with image 3

4. And then click OK button, all the corresponding images with the size as the same as the cells will be replaced with the original text, see screenshots:

doc replace text with image 4  2 doc replace text with image 5

Notes:

1. In the above code, you need to change the folder path of the pictures to your need, xPath = "C:\Users\dt\Desktop\Fruits\".

2. If there are no corresponding pictures to match the text, the error N/A will display.


Replace text with corresponding pictures with Kutools for Excel

As the above code difficult to master, here, I will introduce you an easy and powerful tool - Kutools for Excel, with its Match Import Pictures feature, you can quickly and conveniently to insert the pictures to match the list of text.

Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. 

After installing Kutools for Excel, please do as this:

1. Click Kutools Plus > Import & Export > Match Import Pictures, see screenshot:

2. In the Match Import Pictures dialog box, click doc replace text button 1 button to select the range that you want to match with the pictures, see screenshot:

doc replace text with image 7 7

3. Then in the Match Import Pictures dialog, click Add > File or Folder to find the pictures that you want to insert, see screenshot:

doc replace text with image 8 8

4. After inserting the corresponding images, then click Import size button, in the following Import Picture Size dialog, specify one option for the size of your picture. See screenshot:

doc replace text with image 9 9

5. Then click OK > Import, and then choose one cell to locate your relative images from the popped out Match Import Pictures dialog (you can also select the original cell of the text), see screenshot:

doc replace text with image 10 10

6. And then click OK button, all the pictures which match with the text have been inserted into the worksheet, see screenshot:

doc replace text with image 11 11

Notes:

1. If there are no matched pictures with the text, the cell will not insert anything.

2. If you want to insert pictures horizontally, you can check Fill horizontally cell after cell in the Import order section.

Download and free trial Kutools for Excel Now !


Demo: Replace text with corresponding pictures with Kutools for Excel

Kutools for Excel: with more than 300 handy Excel add-ins, free to try with no limitation in 30 days. Download and free trial Now!

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

Description


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!
Comments (0)
No ratings yet. Be the first to rate!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations