0
votes

I have some macros that copy my sheet in excel,and delete certain data. Unfortunately the buttons to which the macros are assigned do not copy over when the macros are run.

Sub CandD()
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Dim sh As Shape, strtSh As Worksheet
    Set strtSh = ActiveSheet
    Sheets("BM Condition").Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Name = "BM Condition" & Sheets.Count - 1
    Range("E14:E33,I14:I33,M14:M33").ClearContents
    For Each sh In ActiveSheet.Shapes
        sh.Delete
    Next sh
    strtSh.Select

    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
End Sub

This is the macro I am using. I have very limited VBA experience and am not finding google very helpful. Could someone recommend a fix for my buttons not copying over?

EDIT: I forgot to mention that when manually copying the buttons remain. I am not sure why this is.

1
Get rid of the sh.Delete (and the loop around) - FunThomas

1 Answers

-1
votes

As FunThomas mentioned, I've tried and tested the following without any errors:

Sub CanD()
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    Dim sh As Shape, strtSh As Worksheet
    Set strtSh = ActiveSheet

    Sheets("BM Condition").Copy After:=Sheets(Sheets.Count)
    ActiveSheet.Name = "BM Condition" & Sheets.Count - 1

    Range("E14:E33,I14:I33,M14:M33").ClearContents

    strtSh.Select
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
End Sub