Shapes in cells

Status
Not open for further replies.

fredrerik84

Active Member
Joined
Feb 26, 2017
Messages
383
So I have this code that first deletes any old shapes (if any) then inserts new shape after. this code was not made by me and i'm having some troubles improving it..

originally it work like this:
cell G27 has a dropdown list and shape gets inserted into cell f27 , Im trying to get remake the code to put the shape straight into g27 removing the need for helper cell f27. I've been somewhat successful. here is my somewhat working code:

Rich (BB code):
            If Not Cell Is Nothing Then
                For Each shp In Shapes
                    If Round(shp.Left, 0) = Round(Target.Offset(0, 0).Left, 0) And Round(shp.Top, 0) = Round(Target.Offset(0, -1).Top, 0) Then
                        shp.Delete
                        Exit For
                    End If
                Next shp
                
                For Each shp In dws.Shapes
                    If shp.Left = Cell.Offset(0, 1).Left And shp.Top = Cell.Offset(0, 1).Top Then
                        Set nShp = shp.Duplicate
                        nShp.Cut
                        ActiveSheet.Paste
                        Application.CutCopyMode = 0
                        flag = True
                        Exit For
                    End If
                Next shp
                If flag Then
                    With Selection
                        .Left = Target.Offset(0, 0).Left
                        .Top = Target.Offset(0, -1).Top
                        .Width = Target.Offset(0, -1).Width
                        .Height = Target.Offset(0, -1).Height
                        Target.Select
                    End With
                End If
            End If


Ive highlighted problem area in red. This is the part that remove the old shape but after changing the shape location placement that line does not work as intended.

Does anyone see what missing for this code to work ?
the only change I have done to this code is here:

.Left = Target.Offset(0, -1).Left
to
.Left = Target.Offset(0, 0).Left

any help making me fix this would be much appreciated :)
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Re-posted: https://www.mrexcel.com/forum/excel-questions/1021628-delete-shape-before-inserting-new-one.html

Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread. Per forum rules, posts of a duplicate nature will be locked or deleted (rule #12 here: Forum Rules).
If you do not receive a response, you can "bump" it by replying to it again, though we advise you to wait 24 hours before doing and not to bump a thread more than once a day.

I am closing this one down and leaving the other open.
 
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

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