Help with Shape Fill

Gregm66

Board Regular
Joined
Jan 23, 2016
Messages
170
Hi All,
I am wondering if it is at all possible to fill 2 shapes with a picture based on a cell value, using vba.
I am currently using vba to display images based on another cell value and this is working fine. This uses the
Code:
Private Sub WorkSheet_Change(ByVal Target As Range)
Dim MyPict As Picture
Dim PictureLoc As String
Dim MyPict1 As Picture
Dim PictureLoc1 As String
If Target.Address = Range("M4").Address Then
ActiveSheet.Pictures.Delete
PictureLoc = "C:\Users\Greg\Documents\DVD Covers\" & Range("M4").Value & ".jpg"
With Range("B4")
Set MyPict = ActiveSheet.Pictures.Insert(PictureLoc)
'.RowHeight = MyPict.Height
MyPict.Top = .Top
MyPict.Left = .Left
MyPict.Width = 400
MyPict.Height = 350
MyPict.Placement = xlMoveAndSize
End With
End If
End Sub

My shape is called "Header" and "Header1"
My Cell that this will look at is I7.. This cell contains a drop down list with the selections of either "Music" or "Movies"
If this cell changes then I want shape Header to change its background image. same for Shape1.

I hope I have explained this enough for everyone to understand.

Any help greatly appreciated.
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Something like this will let the user entry in I7 determine which picture is used for a shape's fill.
This is for one picture. Similar code could handle the second shape.
Code:
Sub Macro1()
    Dim oneShape As Shape
    Dim picPath As String
    
    Select Case Sheet1.Range("i7").Value
        Case "a"
            picPath = "Macintosh HD:Users:michaelerickson:Desktop:temp:111_1000.jpg"
        Case "b"
            picPath = "Macintosh HD:Users:michaelerickson:Desktop:temp:517_160.jpg"
    End Select
    
    With ActiveSheet.Shapes(1)
        .Fill.UserPicture picPath
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,829
Messages
6,181,222
Members
453,024
Latest member
Wingit77

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