+ Reply to Thread
Results 1 to 1 of 1

Macro to copy and assign other macros

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-05-2012
    Location
    Stockholm
    MS-Off Ver
    Excel 2010
    Posts
    162

    Macro to copy and assign other macros

    Hello,

    I'm trying to create a macro (M1) where I copy everything from one sheet (A) to another sheet (B). In sheet A there are a number of buttons that have macros assigned to them. When copying all data from A to B, the buttons are also copied. For the copied buttons to work in sheet B, they need to be assigned to a macro (M2) specific for that sheet (B), and this action is also included in the macro (M1).

    When I record the macro (M1) everything works fine, but when I try running the macro (M1), it looks very strange and it does not work.

    I've attached the code for the complete macro (M1) and highlighted where it appears to go wrong.

    Sub Copy_Budget_to_Forecast_2()
    '
    ' Copy_Budget_to_Forecast_2 Macro
    '
    
    '
        Sheets("Forecast (w. planning)").Select
        ActiveSheet.Shapes.Range(Array("myButton1")).Select
        Selection.Delete
        ActiveSheet.Shapes.Range(Array("myButton2")).Select
        ActiveWindow.SmallScroll Down:=11
        ActiveSheet.Shapes.Range(Array("myButton2", "myButton3")).Select
        ActiveWindow.SmallScroll Down:=20
        ActiveSheet.Shapes.Range(Array("myButton2", "myButton3", "mybutton4")). _
            Select
        ActiveWindow.SmallScroll Down:=10
        ActiveSheet.Shapes.Range(Array("myButton2", "myButton3", "mybutton4", _
            "mybutton5")).Select
        ActiveWindow.SmallScroll Down:=6
        ActiveSheet.Shapes.Range(Array("myButton2", "myButton3", "mybutton4", _
            "mybutton5", "mybutton6")).Select
        ActiveWindow.SmallScroll Down:=-2
        Selection.Delete
        ActiveWindow.SmallScroll Down:=-1
        ActiveWindow.LargeScroll Down:=-1
        ActiveWindow.SmallScroll Down:=-20
        Sheets("Budget (w. plan)").Select
        Range("A8:DE150").Select
        Selection.Copy
        Sheets("Forecast (w. planning)").Select
        Range("A8").Select
        ActiveSheet.Buttons.Add(272.25, 145.5, 63.75, 21).Select
        ActiveSheet.Buttons.Add(272.25, 366.75, 63.75, 21).Select
        ActiveSheet.Buttons.Add(272.25, 573.75, 63.75, 21).Select
        ActiveSheet.Buttons.Add(272.25, 779.25, 63.75, 21).Select
        ActiveSheet.Buttons.Add(272.25, 955.5, 63.75, 21).Select
        ActiveSheet.Buttons.Add(272.25, 1103.25, 63.75, 21).Select
        ActiveSheet.Paste
        Range("A7").Select
        ActiveSheet.Shapes.Range(Array("myButton1")).Select
        Application.CutCopyMode = False
        Selection.OnAction = "Sheet5.InsertRowByButton"
        ActiveSheet.Shapes.Range(Array("myButton2")).Select
        Selection.OnAction = "Sheet5.InsertRowByButton"
        ActiveWindow.SmallScroll Down:=16
        ActiveSheet.Shapes.Range(Array("myButton3")).Select
        Selection.OnAction = "Sheet5.InsertRowByButton"
        ActiveWindow.SmallScroll Down:=19
        ActiveSheet.Shapes.Range(Array("mybutton4")).Select
        Selection.OnAction = "Sheet5.InsertRowByButton"
        ActiveWindow.SmallScroll Down:=10
        ActiveSheet.Shapes.Range(Array("mybutton5")).Select
        Selection.OnAction = "Sheet5.InsertRowByButton"
        ActiveWindow.SmallScroll Down:=5
        ActiveSheet.Shapes.Range(Array("mybutton6")).Select
        ActiveWindow.LargeScroll Down:=-3
        Range("A7").Select
    End Sub
    Can anyone help me to see why it goes wrong?
    Last edited by D-smoke; 02-13-2013 at 09:36 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1