+ Reply to Thread
Results 1 to 8 of 8

run macro after choosing in a dropdown list

  1. #1
    Registered User
    Join Date
    08-28-2008
    Location
    Switzerland
    Posts
    24

    run macro after choosing in a dropdown list

    Hello all

    I have a dropdown list with 6 options (Cell link H5). If the user of my file chooses option 6, line 23 and 24 of my input sheet should be unhidden. If the user chooses the options 1 to 5, line 23 and 24 should be hidden. How can this be done? I have already a code but it doesn't work!

    I made 2 macros which should be running automatically, depending the choose in the dropdownlist:

    Sub UnhideNameOfDisease()
    Sheets("Input").Activate
    If Range("H5").Value = 6 Then
    Rows("23:25").Hidden = False
    End If
    End Sub

    Sub HideNameOfDisease()
    Sheets("Input").Activate
    If Range("H5").Value < 6 Then
    Rows("23:25").Hidden = True
    End If
    End Sub

    This macro is to run one of them:

    Private Sub Worksheet_Change(ByVal Target As Excel.Range)

    If Target.Address <> "$H$5" Then Exit Sub

    Select Case Target.Value
    Case "1"
    Call HideNameOfDisease
    Case "2"
    Call HideNameOfDisease
    Case "3"
    Call HideNameOfDisease
    Case "4"
    Call HideNameOfDisease
    Case "5"
    Call HideNameOfDisease
    Case "6"
    Call UnhideNameOfDisease
    Case Else
    End Select

    End Sub

    Thanxs for answers!!!

    Greets

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    Your code works fine.
    Please see what is your activecell when you choose an option from dropdown list. If activecell is not H5 your code will not work.

    Try also to do this:
    Open Visual basic editor (alt + F11)
    Go on immediate wirndow (ctrl + g)
    type:
    Please Login or Register  to view this content.
    and press Enter.

    I hope it can help you.

    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    08-28-2008
    Location
    Switzerland
    Posts
    24
    Thanxs for your answer, but it still doesn't work... Am i wright, if I have the macro _change in the Sheet5(Input) space and the two other macros in Module1 space?

  4. #4
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    If you have macros in Module1 you need to use 'Module1.' as prefix to call the macro, for example:
    To call macro 'UnhideNameOfDisease' of Module1 you need to write 'Call Module1.UnhideNameOfDisease' (you can also use '!' instead of '.').

    Regards,
    Antonio

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,461
    this works for me.

    Please Login or Register  to view this content.
    Please use code tags in future.
    Cheers
    Andy
    www.andypope.info

  6. #6
    Registered User
    Join Date
    08-28-2008
    Location
    Switzerland
    Posts
    24
    ok, now it works if i enter the numbers myself. But is there a way that it works if I choose in the dropdown list? Because if i don't press the enter button, nothing happens...

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,461
    I assume the dropdown list is a data validation dropdown and not a control?

  8. #8
    Registered User
    Join Date
    08-28-2008
    Location
    Switzerland
    Posts
    24
    its the combobox from the "Forms" Toolbar. Is there another list with the same attributes?

+ 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. COUNTIF referencing different named ranges in dropdown list
    By dutton in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-07-2013, 10:01 AM
  2. Macro to select Names from dropdown list?
    By leeb1977 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-13-2008, 09:00 AM
  3. Limited Characters in VBA dropdown list
    By nomad3rider in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-29-2007, 06:10 PM
  4. Need a macro to search and remake any list
    By mfrancis in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-21-2006, 04:54 AM
  5. Macro from List?
    By rufusf in forum Excel General
    Replies: 1
    Last Post: 10-06-2006, 08:35 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