Check If a Cell contain Image/Picture

This post will guide you how to check if a specific cell contains an image or picture in excel. Is it possible to check if a cell contains an image. This post will guide you how to define a User Defined Function to determine if an image exists in a specified cell. Or how to use VBA Macro code to check if a cell contains an image.

The simplest method is to create a user defined function to check if a cell contains an image file, and return 1 if image exists in cell. Otherwise, returns 0. You can follow these steps:

#1 open your excel workbook and then click on “Visual Basic” command under DEVELOPER Tab, or just press “ALT+F11” shortcut.

Get the position of the nth using excel vba1

#2 then the “Visual Basic Editor” window will appear.

#3 click “Insert” ->”Module” to create a new module

convert column number to letter3

#4 paste the below VBA code into the code window. Then clicking “Save” button.

check if a cell contain image2

Function CellImageCheck(CellToCheck As Range) As Integer
    ' Return 1 if image exists in cell, 0 if not
    Dim wShape As Shape
    For Each wShape In ActiveSheet.Shapes
        If wShape.TopLeftCell = CellToCheck Then
            CellImageCheck = 1
        Else
            CellImageCheck = 0
        End If
    Next wShape
End Function

#5 back to the current worksheet, try to enter the below formula in Cell D6.

=CellImageCheck(B6)

check if a cell contain image1

 

You can also use the following VBA code to check if a cell contains an image.  You just need to repeat the above 1-3 steps firstly, then continue to do the following steps:

#1 paste the below VBA code into the code window. Then clicking “Save” button.

check if a cell contain image3

Sub CellImageCheck()
    Dim checkRange As Range
    Dim x As Shape
    Dim flag As Boolean
    On Error Resume Next
    Set checkRange = Application.InputBox("please enter one cell that you want to check", "CellImageCheck", Selection.Address, , , , , 8)
    If checkRange Is Nothing Then Exit Sub
        flag = False
        For Each x In ActiveSheet.Shapes
            If x.TopLeftCell.Address = checkRange.Address Then
                flag = True
            End If
        Next
    If flag Then
        MsgBox "Found an image!"
    Else
        MsgBox "No Image"
    End If
End Sub

#2 back to the current worksheet, then run the above excel macro. Click Run button.

check if a cell contain image4

#3 select one cell that you want to check, such as: B6

check if a cell contain image5

#4 Let’s see the result:

check if a cell contain image6

 

Comments

So empty here ... leave a comment!

Leave a Reply

Your email address will not be published. Required fields are marked *

Sidebar