Check to find if there is a picture above a certain cell

treygon

New Member
Joined
Aug 13, 2010
Messages
16
I am pasting shapes to a specific cell range. However, I first want to find out if there is already a shape in (on top) the cell range. If there is already a shape, I need to identify it and delete it so I can paste a new shape there. IF there is no shape located in the range, then to go ahead and past a shape there.

For example,

Sheets(Sheet1).Range("A1") is where I am pasting shapes.

I want to first identify if there is already a picture located at Range("A1"). If there is, delete it, and then paste the new picture.

I am using the following code to paste the new shape:
Code:
    Highlight_Left_Ref = Worksheets("Client Report").Range("HighlightRef").Left - 5.25
    Highlight_Top_Ref = Worksheets("Client Report").Range("HighlightRef").Top - 3
      
    Sheets("StateHighlights").Select
    Sheets("StateHighlights").Shapes("52One").Copy
    Application.Goto Sheets("Client Report").Range("HighlightRef")
    ActiveSheet.Paste
    Sheets("Client Report").Shapes("52One").Left = Highlight_Left_Ref
    Sheets("Client Report").Shapes("52One").Top = Highlight_Top_Ref
Using Excel 2007
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Maybe something like this...

Code:
[font=Verdana][color=darkblue]Option[/color] [color=darkblue]Explicit[/color]

[color=darkblue]Sub[/color] test()

    [color=darkblue]Dim[/color] Shp [color=darkblue]As[/color] Shape
    [color=darkblue]Dim[/color] MyShape [color=darkblue]As[/color] Shape
    [color=darkblue]Dim[/color] MyRange [color=darkblue]As[/color] Range

    [color=darkblue]Set[/color] MyShape = Sheets("State Highlights").Shapes("52One")
    
    [color=darkblue]Set[/color] MyRange = Sheets("Client Report").Range("A1")
    
    [color=darkblue]With[/color] Sheets("Client Report")
        [color=darkblue]For[/color] [color=darkblue]Each[/color] Shp [color=darkblue]In[/color] .Shapes
            [color=darkblue]If[/color] Shp.TopLeftCell.Address = MyRange.Address [color=darkblue]Then[/color]
                Shp.Delete
                MyShape.Copy
                MyRange.PasteSpecial
                [color=darkblue]Exit[/color] [color=darkblue]Sub[/color]
            [color=darkblue]End[/color] [color=darkblue]If[/color]
        [color=darkblue]Next[/color] Shp
    [color=darkblue]End[/color] [color=darkblue]With[/color]
    
    MyShape.Copy
    MyRange.PasteSpecial

[color=darkblue]End[/color] [color=darkblue]Sub[/color]
[/font]
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,345
Members
452,907
Latest member
Roland Deschain

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