change colour of picture based on cell value

mickyflash

Board Regular
Joined
Jan 29, 2009
Messages
77
hello again guys

I have found this video of Bills that explains how I could dynamically change the .width & .Height of a shape in excel, but I am struggling to convert this to the shapes colour?

There would be only 2 options, if the linked cell is = to TRUE to view the picture In colour, or greyscale if FALSE

Thanks in advance for your help
 
Try this

VBA Code:
Sub ChangeColour()
    ActiveSheet.Pictures.Delete
    Dim lastRow As Long, Pic As Variant, N As Variant
    Dim URLs As Range, URL As Range
 
    With ActiveSheet
        lastRow = .Cells(Rows.Count, "A").End(xlUp).Row
        Set URLs = .Range("A2")     ' this range needs amending ???
    End With

    For Each URL In URLs
        URL.Offset(0, 4).Select
        URL.Parent.Pictures.Insert URL.Value
        DoEvents

        Set Pic = ActiveSheet.Shapes(ActiveSheet.Shapes.Count)
        N = Pic.Name
        MsgBox N
        If Not URL.Offset(, 1) Then ActiveSheet.Shapes(N).PictureFormat.ColorType = 2      
    Next
   
End Sub

What does message box return
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Weird............ but it explains why we are getting nowhere!!

Now run this ...

VBA Code:
Sub ChangeColour()
    ActiveSheet.Pictures.Delete

    Dim lastRow As Long, Pic As Variant, N As Variant
    Dim URLs As Range, URL As Range
    
    With ActiveSheet
        lastRow = .Cells(Rows.Count, "A").End(xlUp).Row
        Set URLs = .Range("A2")     ' this needs amending ???
    End With

    For Each URL In URLs
        URL.Offset(0, 4).Select
        URL.Parent.Pictures.Insert URL.Value
        DoEvents
    Next
    Dim shp As Shape, msg As String
    For Each shp In ActiveSheet.Shapes
        msg = msg & vbCr & shp.Name
    Next
    Debug.Print  Now & vbCr & msg
End Sub

What was printed to the immediate window ?
- paste whatever is in immediate window into your reply
- in VBA editor you can see immediate window with CTRL G
 
Upvote 0
03-Dec-19 3:58:22 PM

Chart 7
Chart 8
Picture 11
Drop Down 3
03-Dec-19 3:58:28 PM

Chart 7
Chart 8
Picture 12
Drop Down 3
03-Dec-19 3:58:59 PM

Chart 7
Chart 8
Picture 13
Drop Down 3
 
Upvote 0
chart 7 and chart 8 are graphs on the worksheet but are irrelevent to this and not important if they are causing the issue
 
Upvote 0
its saying drop down 4 now!

The player name is selected by a drop down data validation.
The result is then VLOOKUP'd to a table which pulls the image link address into A2
 
Upvote 0
OK
- at least we understand why the code was not returning the picture
- it (corrrectly) returned the last shape added BUT there is nothing in your code inserting a dropdown

What is causing a new dropdown to be inserted ?
- is any event code triggered when cell values change in the sheet ?
- look in the sheet code module or in ThisWorkbook module
- I can amend the code without the anser but I would like to understand what is going on behind the scenes

I am out of time for today but I will post amended code tomorrow :)
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,519
Members
448,968
Latest member
Ajax40

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