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
 
Please create a NEW workbook and put the code below in a module in that workbook
- I want to eliminate risk of any other history or code getting in the way

Place links in A2:A6 and TRUE/FALSE in B2:B6

Run the code and let me know
thanks

VBA Code:
Public Sub Add_Images_To_Cells()
   
    Dim lastRow As Long
    Dim URLs As Range, URL As Range, shpCel As Range
    Dim shp As Shape, N As String
   
    With ActiveSheet
        .Pictures.Delete
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
        Set URLs = .Range("A2:A" & lastRow)

        For Each URL In URLs
            URL.Offset(0, 4).Select
            On Error Resume Next
            URL.Parent.Pictures.Insert URL.Value
            DoEvents
            Set shp = .Shapes(.Shapes.Count)
            If Not URL.Offset(, 1) Then shp.PictureFormat.ColorType = 2
        Next URL
    End With

     MsgBox "completed " & Now
End Sub
 
Upvote 0

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
OK - we now need to do the same thing in your original workbook

- delete the previous code in the original workbook and put the new code there in its place
- run and let me know
 
Upvote 0

Forum statistics

Threads
1,214,861
Messages
6,121,973
Members
449,059
Latest member
oculus

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