+ Reply to Thread
Results 1 to 7 of 7

SubRoutines

  1. #1
    Forum Contributor
    Join Date
    10-17-2018
    Location
    Knoxville, TN
    MS-Off Ver
    Office 365
    Posts
    214

    SubRoutines

    Is it possible to have two Sub Routines with the same name? Example: I am using the following for two different reasons: Private Sub Worksheet_Change(ByVal Target As Range). I am using each for a drop-down list using the case statement

    This one opens the three different subroutines based on a drop-down list.
    It works based on a drop-down with Easy, Med, Hard as the selection and runs the subroutines.

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("Y10")) Is Nothing Then
    Select Case Range("Y10")
    Case "Easy": RandomEasy
    Case "Med": RandomMedium
    Case "Hard": RandomHard
    End Select
    End If
    End Sub




    This is another one I use for another reason but does not work and it uses a drop-down list.

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("Q8")) Is Nothing Then
    Select Case Range("Q8")
    Case "P1": CopyPuzzle1 'The P1, P2, P3 are in the drop-down represents a puzzle from another tab that is copied/pasted onto the main worksheet
    Case "P2": CopyPuzzle2 'The CopyPuzzle1, 2, 3 will copy the puzzle and paste.
    Case "P3": CopyPuzzle3

    End Select
    End If
    End Sub

    These subroutines work if I use a macro button, but get nothing using a drow-down. Don't even get an error or debug request. Nothing happens
    Both are located in the same Module in the worksheet where you click on the sheet's tab and then view code. Both are exactly the same, but why doesn't one work?

    Thanks

    Jerry

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: SubRoutines

    The change event handlers need to go in the Sheet module, not a standard module. Event handling must be enabled.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    10-17-2018
    Location
    Knoxville, TN
    MS-Off Ver
    Office 365
    Posts
    214

    Re: SubRoutines

    TMS, they are located on the sheet and not in a module, or are you saying that the subroutines should go there also? and not familiar with enabling the event

  4. #4
    Forum Contributor
    Join Date
    10-17-2018
    Location
    Knoxville, TN
    MS-Off Ver
    Office 365
    Posts
    214

    Re: SubRoutines

    TMS - I found my error, you can't have that named routine twice so I changed the word "WorkSheet" to "WorkSheets" because it said it was an ambiguous name, so I will change the one for the Easy, Medium, Hard to run from Marco buttons since there is only 3 to choose from, but on my other one I have 25 puzzles involved and actually have 25 macro buttons on the worksheet, and that ain't pretty, so the drop-down is what I really needed.

    Thanks for your help

    Jerry

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: SubRoutines

    You need to do it this way:

    Please Login or Register  to view this content.
    Take the space out of "Sel ect"

  6. #6
    Forum Contributor
    Join Date
    10-17-2018
    Location
    Knoxville, TN
    MS-Off Ver
    Office 365
    Posts
    214

    Re: SubRoutines

    Ok, that space was a copy-paste error, but from the way you have it, I can have just the "one" Private Sub Worksheet_Change(ByVal Target As Range) and add as many dropdowns as I have without repeating that Private part. Thanks, cool, I am going to copy this and save it.

    thanks

    Jerry

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,445

    Re: SubRoutines

    No, I put the spaces in because the security software wouldn’t allow the Select statements.

+ 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. [SOLVED] Do While in between two subroutines
    By hassanm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-08-2015, 05:08 AM
  2. [SOLVED] Running subroutines
    By tjgrassi in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-27-2014, 11:54 AM
  3. [SOLVED] can't debug some subroutines in my project, locked subroutines
    By florin_excel in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-28-2012, 01:16 PM
  4. Combining Subroutines
    By jj72uk in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-18-2009, 04:02 AM
  5. Use of Screenupdating on subroutines
    By gjcase in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-21-2009, 12:46 PM
  6. Calling SubRoutines
    By diannk in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-18-2008, 03:51 PM
  7. userforms and subroutines
    By stanigator in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-04-2007, 03:28 PM

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