Picture Copy/Insert Based on Cell Value

ryan_law2000

Well-known Member
Joined
Oct 2, 2007
Messages
738
Hello, I cant seem to get anything to work for this.

If Sheet1 A5 = "TEST A"
Delete current picture in $A$7
Then Copy "Picture 1" from Sheet2
Insert Picture into sheet1$A$7

If Sheet1 A5 = "TEST B"
Delete current picture in $A$7
Then Copy "Picture 2" from Sheet2
Insert Picture into sheet1$A$7

I have about 50 possible picture so i would continue on from there

Any ideas on how this could be done?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
First, set up a table that lists the test (ie. TEST A), along with the corresponding picture name (ie. Picture 1). For this example, let's assume that Sheet2 contains this list in A2:B50, as follows...

TEST APicture 1
TEST BPicture 2
etc...

<COLGROUP><COL style="WIDTH: 74pt; mso-width-source: userset; mso-width-alt: 3584" span=2 width=98><TBODY>
</TBODY>

Then try the following macro...

Code:
Option Explicit
Sub InsertPicture()
    Dim objPic      As Picture
    Dim wksSource   As Worksheet
    Dim wksDest     As Worksheet
    Dim varPicName  As Variant
    
    Set wksSource = Worksheets("Sheet2")
    Set wksDest = Worksheets("Sheet1")
    
    varPicName = Application.VLookup(wksDest.Range("A5").Value, wksSource.Range("A2:B50"), 2, 0)
    
    If IsError(varPicName) Then
        MsgBox "The picture is not available.", vbExclamation
        Exit Sub
    End If
    
    For Each objPic In wksDest.Pictures
        If objPic.TopLeftCell.Address = "$A$7" Then
            objPic.Delete
            Exit For
        End If
    Next objPic
    
    wksSource.Pictures(varPicName).Copy
    wksDest.Range("A7").PasteSpecial
    
End Sub

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,214,567
Messages
6,120,268
Members
448,953
Latest member
Dutchie_1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top