+ Reply to Thread
Results 1 to 2 of 2

Using a macro to create a macro?

Hybrid View

  1. #1
    Registered User
    Join Date
    05-01-2012
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    2

    Smile Using a macro to create a macro?

    Hi, all,

    I've been able to use all the help previously provided to others to create a bunch of macros that are helping me out with this workbook I'm creating, and I'm hoping that you'll be able to help me with this last part.

    I have a table at the top of the page listing my current 6 coachees/reviewees (currently with names from MTV's "Teen Wolf"). I have added a macro that will insert a row at the bottom of the table, along with a sequential ID number, for any new subordinates I get.

    Each coachee/reviewee has their own table below the top table, where I will put relevant HR data, their goals for industry credentials, performance goals, etc. I would like to have a button for each person at the top, assigned to a macro which take me to their table below. I have 14 coachee/reviewee tables generated, so the creation of those isn't an issue (if I ever get more than 14 of either, I'll have bigger concerns than creating a new table)

    The issue is that I would like to have a button generated if I need to add new coachees/reviewees.

    I will need to do this for 2 worksheets total, but as long as I get one of the sheets done, I can rig it to work on the other worksheet. The file is attached.

    Please let me know if you have any guidance on how to tackle this problem.

    (If you have ideas about managing the size, I'd be happy to make those changes immediately!)
    Attached Files Attached Files

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Using a macro to create a macro?

    Why do you need code to write code?

    Do you even need multiple macros?

    For example you could have one AddCredit macro that can be assigned to each button.

    Then you can use Application.Caller to find the location of the button that's called the code, and you can use that to add a new credential line.

    Something like this.
    Sub AddCred()
    
        Dim Lr As Integer
        
        Dim rng As Range
        
        Set rng = Worksheets("PC&D Tracker Coach").Shapes(Application.Caller).TopLeftCell
        
        Lr = rng.Offset(2).End(xlDown).Row
         
        Application.ScreenUpdating = False
    
        Rows(Lr + 1).Insert Shift:=xlDown
        Cells(Lr + 1, "B") = Cells(Lr, "B") + 1
        Rows(Lr).Copy
        Rows(Lr + 1).PasteSpecial Paste:=xlPasteFormats
        Application.CutCopyMode = False
        ActiveCell.FormulaR1C1 = "."
        Cells(Lr + 1, "B").Select
    
        Application.ScreenUpdating = False
    
    End Sub
    I've just assigned that code to all the buttons for adding credentials and it works.

    You could probably do something similar for the other buttons, in fact you might be able to use that code for all the buttons that add a row.
    If posting code please use code tags, see here.

+ 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