Insertion of picture by xls formula/ naming the picture

Joined
Jun 7, 2011
Messages
15
Can anybody give me the idea that how to put the picture with a formula in xls sheet,
or if i click on one cell than respective picture should display in another cell

How it is possible

Thanks to you in advance.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
How about putting the picture as the background for a cell comment?

... right-click comment border, Format Comment, Colors and Lines, Fill Color drop-down, Fill Effects, Picture, Select Picture.
 
Upvote 0
Try something like:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Pic As Object
Dim Rng As Range
Dim MyImageFolderPath As String
If Selection.Cells.Count > 1 Then Exit Sub
 
For Each Pic In ActiveSheet.Pictures
'Deletes the old images:
    Pic.Delete
Next Pic
Set Rng = Range("A1:D5")
MyImageFolderPath = "C:\My Images\"   'Change to match your folder
'Inserts the desired image:
Set Pic = ActiveSheet.Pictures.Insert(MyImageFolderPath & Target.Value)
'Adjusts the image to match the range:
With Pic
    .Top = Rng.Top
    .Left = Rng.Left
    .Height = Rng.Height
    .Width = Rng.Width  'Comment if you  want the height to set the size
End With
End Sub
The code deletes all the old images from the sheet and adds the new image from the set image folder.

If you already have all your images in your workbook use the following code instead:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim Pic As Object
Dim Rng As Range
On Error Resume Next
If Selection.Cells.Count > 1 Then Exit Sub
 
For Each Pic In ActiveSheet.Pictures
'Hides all the images:
    Pic.Visible = False
Next Pic
Set Rng = Range("A1:D5")    'Comment if you want to show the images where they are
MyImageFolderPath = "C:\Documents and Settings\All Users\Tiedostot\Omat kuvatiedostot\Kuvanäytteet\"
'Inserts the desired image:
Set Pic = ActiveSheet.Shapes(Target.Value)
'Adjusts the image to match the range:
With Pic
    .Visible = True
    .Top = Rng.Top
    .Left = Rng.Left
    .Height = Rng.Height
 '   .Width = Rng.Width  'Comment if you  want the height to set the size
End With
End Sub
Paste the code into the worksheet module of your workbook.
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

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