Insert Image URL Images Into Cells

L

Legacy 361036

Guest
I have a dropdown that currently everything on a dashboard is changing against depending on which month is selected.

I also have images that I want to show. The images are all hosted online. I have code from another thread (http://www.mrexcel.com/forum/excel-questions/604604-insert-image-url-images-into-cells.html) that lets me embed images based on a URL (A1) in B1. I have several problems that I'd like help to figure out if possible.


  1. I need the images to load based on which month is selected. Currently I'm thinking I can hide the URLs in Column A and have them load based on the dropdown. Then the image would load based on that dynamic cell loading the URL. I'm using INDEX-MATCH right now and it's not working with the macro I have. It runs without throwing errors, but no picture loads.
  2. Each time the macro runs, I'd like to clear the old pictures. Right now each time I run it, it loads the pictures over the old one.
  3. Ideally I'd like the image to load from the URL online each time and not embed. Is that even possible?

Summary: Need a macro to remove images, then load a new image from the web (and not embed itself) based on a dynamic cell with a URL.

Currently I have the URLs loading in Column A on various rows, and I want the images to show in Column B.

Code:
Sub IMAGE()    
Dim Rng As Range
    Dim Cell As Range
    Dim ws As Worksheet
    Dim s As Shape
    Set ws = ActiveSheet
    Application.ScreenUpdating = False
    Show Picture = False
    Set Rng = Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
    For Each Cell In Rng
        With Cell
            On Error Resume Next
           Set s = ws.Shapes.AddPicture(Cell.Value, False, True, Cell.Offset(, 1).Left, Cell.Offset(, 1).Top, Cell.Offset(, 1).Height, Cell.Offset(, 1).Width)
            
            If Err <> 0 Then
                Err.Clear
            Else
            With .Offset(, 1)
                    s.Top = .Top + 5
                    s.Left = .Left + 5
                    s.Height = 220
                    s.Width = 227
                    End With
            End If
            On Error GoTo 0
        End With
    Next Cell
   
    Application.ScreenUpdating = True
End Sub

My skills with VB are limited, just little tweaks. But I'd love to learn. Thank you!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I have a dropdown that currently everything on a dashboard is changing against depending on which month is selected.

I also have images that I want to show. The images are all hosted online. I have code from another thread (http://www.mrexcel.com/forum/excel-questions/604604-insert-image-url-images-into-cells.html) that lets me embed images based on a URL (A1) in B1. I have several problems that I'd like help to figure out if possible.


  1. I need the images to load based on which month is selected. Currently I'm thinking I can hide the URLs in Column A and have them load based on the dropdown. Then the image would load based on that dynamic cell loading the URL. I'm using INDEX-MATCH right now and it's not working with the macro I have. It runs without throwing errors, but no picture loads.
  2. Each time the macro runs, I'd like to clear the old pictures. Right now each time I run it, it loads the pictures over the old one.
  3. Ideally I'd like the image to load from the URL online each time and not embed. Is that even possible?

Summary: Need a macro to remove images, then load a new image from the web (and not embed itself) based on a dynamic cell with a URL.

Currently I have the URLs loading in Column A on various rows, and I want the images to show in Column B.

Code:
Sub IMAGE()    
Dim Rng As Range
    Dim Cell As Range
    Dim ws As Worksheet
    Dim s As Shape
    Set ws = ActiveSheet
    Application.ScreenUpdating = False
    Show Picture = False
    Set Rng = Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row)
    For Each Cell In Rng
        With Cell
            On Error Resume Next
           Set s = ws.Shapes.AddPicture(Cell.Value, False, True, Cell.Offset(, 1).Left, Cell.Offset(, 1).Top, Cell.Offset(, 1).Height, Cell.Offset(, 1).Width)
            
            If Err <> 0 Then
                Err.Clear
            Else
            With .Offset(, 1)
                    s.Top = .Top + 5
                    s.Left = .Left + 5
                    s.Height = 220
                    s.Width = 227
                    End With
            End If
            On Error GoTo 0
        End With
    Next Cell
   
    Application.ScreenUpdating = True
End Sub

My skills with VB are limited, just little tweaks. But I'd love to learn. Thank you!

I solved this, for anyone who is interested, it works beautifully. But note that this will *not* work on Excel for Mac.

Code:
Sub remove_images()

    Dim pic As Picture
    
    For Each pic In ActiveSheet.Pictures
        If pic.Name <> "logo" Then
            pic.Delete
        End If
    Next pic
    
End Sub


Sub Worksheet_Calculate()
    Dim Rng As Range
    Dim Cell As Range
    Dim ws As Worksheet
    Dim s As Shape
    Set ws = ActiveSheet
    Application.ScreenUpdating = False
    
    remove_images
    
    Set Rng = Range("A3:A" & Range("A" & Rows.Count).End(xlUp).Row)
    For Each Cell In Rng
        With Cell
            On Error Resume Next
           Set s = ws.Shapes.AddPicture(Cell.Value, False, True, Cell.Offset(, 1).Left, Cell.Offset(, 1).Top, Cell.Offset(, 1).Height, Cell.Offset(, 1).Width)
            
            If Err <> 0 Then
                Err.Clear
            Else
            With .Offset(, 1)
                    s.Top = .Top + 5
                    s.Left = .Left + 5
                    s.Height = 220
                    s.Width = 227
                    End With
            End If
            On Error GoTo 0
        End With
    Next Cell
   
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,545
Messages
6,120,132
Members
448,947
Latest member
test111

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