+ Reply to Thread
Results 1 to 5 of 5

macros should run based off of drop down menu change, is failing to run

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-02-2012
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    452

    macros should run based off of drop down menu change, is failing to run

    ITraining Stats, upload version.xlsm

    I have this macro which should insert data from the Calculator sheet to the appropriate sheet based off of whatever sheet name is selected from the drop down menu at cell Z18 of the Calculator sheet. However, selecting any sheet name from the drop down menu fails to make the macro run. What am I doing wrong?

    Sub exporttoexercisesheets()
    '
    ' exporttoexercisesheets Macro
    ' This will export R1:R19 to the exercise sheet selected in the dropdown meanu at Z18.
    '
    Select Case Range("Z18")
    
    Case "Prime Bench Main"
    Sheets("Prime Bench Main").Cells(3, Columns.Count).End(xlToLeft).Offset(, 1).Resize(19).Value = Sheets("Calculator").Range("R1:R19").Value
        
    Case "Prime Bench Assist"
    Sheets("Prime Bench Assist").Cells(3, Columns.Count).End(xlToLeft).Offset(, 1).Resize(19).Value = Sheets("Calculator").Range("R1:R19").Value
         
    Case "Prime Bench Supp"
    Sheets("Prime Bench Supp").Cells(3, Columns.Count).End(xlToLeft).Offset(, 1).Resize(19).Value = Sheets("Calculator").Range("R1:R19").Value
          
    Case "2ndary Bench Main"
    Sheets("2ndary Bench Main").Cells(3, Columns.Count).End(xlToLeft).Offset(, 1).Resize(19).Value = Sheets("Calculator").Range("R1:R19").Value
       
    Case "2ndary Bench Assist"
    Sheets("2ndary Bench Assist").Cells(3, Columns.Count).End(xlToLeft).Offset(, 1).Resize(19).Value = Sheets("Calculator").Range("R1:R19").Value
         
    Case "2ndary Bench Supp"
    Sheets("2ndary Bench Supp").Cells(3, Columns.Count).End(xlToLeft).Offset(, 1).Resize(19).Value = Sheets("Calculator").Range("R1:R19").Value
          
    Case "Squat Main"
    Sheets("Squat Main").Cells(3, Columns.Count).End(xlToLeft).Offset(, 1).Resize(19).Value = Sheets("Calculator").Range("R1:R19").Value
            
    Case "Squat Assist"
    Sheets("Squat Assist").Cells(3, Columns.Count).End(xlToLeft).Offset(, 1).Resize(19).Value = Sheets("Calculator").Range("R1:R19").Value
               
    Case "Squat Supp"
    Sheets("Squat Supp").Cells(3, Columns.Count).End(xlToLeft).Offset(, 1).Resize(19).Value = Sheets("Calculator").Range("R1:R19").Value
                  
    Case "Prime DL"
    Sheets("Prime DL").Cells(3, Columns.Count).End(xlToLeft).Offset(, 1).Resize(19).Value = Sheets("Calculator").Range("R1:R19").Value
       
    Case "DL Assist"
    Sheets("DL Assist").Cells(3, Columns.Count).End(xlToLeft).Offset(, 1).Resize(19).Value = Sheets("Calculator").Range("R1:R19").Value
          
    Case "DL Supp"
    Sheets("DL Supp").Cells(3, Columns.Count).End(xlToLeft).Offset(, 1).Resize(19).Value = Sheets("Calculator").Range("R1:R19").Value
    
    End Select
    
    End Sub

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,785

    Re: macros should run based off of drop down menu change, is failing to run

    The code is OK but you aren't doing anything that will run it. You need to add the following code to the Calculator module:

    Public Sub Worksheet_Change(ByVal Target As Range)
    
       If Target.Address = [Z18].Address Then
          Module15.exporttoexercisesheets
       End If
    
    End Sub
    I also highly recommend making this code change in Module15.exporttoexercisesheets, although the code will technically work without it:

    ' Change this
    
    Select Case Range("Z18")
    
    ' to this
    
    Select Case Worksheets("Calculator").Range("Z18")
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,785

    Re: macros should run based off of drop down menu change, is failing to run

    I looked at some other code. You have a bunch of empty Modules that should be removed to clean up. You also have code in Modules like this:

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)

    but that code will only be effective if it is in a worksheet module, as I showed above. It will not be triggered in a Module.

  4. #4
    Forum Contributor
    Join Date
    04-02-2012
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    452

    Re: macros should run based off of drop down menu change, is failing to run

    It works, thank you very much!

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,785

    Re: macros should run based off of drop down menu change, is failing to run

    You're welcome! Thanks for the rep, and thanks for marking your thread Solved!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Locking a formula in a column where the values change based on drop down menu
    By uhm_81 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-20-2014, 09:57 PM
  2. Change value of cell based on a drop down menu option.
    By laxtui in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-10-2013, 07:23 AM
  3. Replies: 1
    Last Post: 12-09-2013, 04:19 PM
  4. Want picture to change based on value selected in drop down menu
    By omartin in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-13-2013, 05:38 PM
  5. [SOLVED] Pivot Table cell/range to change based on drop down menu
    By PippiLaRue in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-13-2013, 09:36 AM

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