+ Reply to Thread
Results 1 to 16 of 16

VBA to auto display drop down list when cell selected

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-21-2012
    Location
    London
    MS-Off Ver
    Office 365 MAC
    Posts
    107

    VBA to auto display drop down list when cell selected

    Hi folks

    As a relative newbie to VBA, with any queries I have I try a web search, forum search and then I post! I am pretty sure my issue is not unique and I am pretty sure there will be another post alredy listed... I never quite know the right phrase to enter in the search tools to find what I am looking for!

    So, after many searches which result in me going nowhere fast, I apologise for the request in advance!

    I have some data validation lists to control data quality in my spreadsheet. As with most users, in order to select a response I must firstly click in to the cell, which in turn displays the dropdown handle, then click the handle and finally make a selection from the list displayed.

    Please can you assist me with - How can I achieve an automatic display of the dropdown as soon as I click in to the relevant cell, using VBA?

    Will the code be cell specific or can it be a more holistic code, which I would imagine slows down the performance?

    I hope the fact that I am a Office for Mac user (Office 365 v16.15) does not further complicate matters... most of the users of my creation will be PC users

    Thank you in advance
    Learner, making mistakes, asking daft questions.

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

    Re: VBA to auto display drop down list when cell selected

    To do this in VBA requires programming to create mouse clicks. It is complicated and in 20 minutes I could not collect enough information to determine the screen coordinates for the click.

    If you are just trying to save clicks, you could use comboboxes instead, which displays the dropdown handle all the time, and you can click directly on that.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    08-21-2012
    Location
    London
    MS-Off Ver
    Office 365 MAC
    Posts
    107

    Re: VBA to auto display drop down list when cell selected

    Quote Originally Posted by 6StringJazzer View Post
    To do this in VBA requires programming to create mouse clicks. It is complicated and in 20 minutes I could not collect enough information to determine the screen coordinates for the click.

    If you are just trying to save clicks, you could use comboboxes instead, which displays the dropdown handle all the time, and you can click directly on that.
    Thank you for the note about combo boxes, I have considered them. Unfortunately there are so many lines in the sheet where I want the functionality it makes the sheet look really messy.

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA to auto display drop down list when cell selected

    Hi Ed

    What is the nature of your data validation?

    A List or a value within a range?
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  5. #5
    Forum Contributor
    Join Date
    08-21-2012
    Location
    London
    MS-Off Ver
    Office 365 MAC
    Posts
    107

    Re: VBA to auto display drop down list when cell selected

    Quote Originally Posted by mehmetcik View Post
    Hi Ed

    What is the nature of your data validation?

    A List or a value within a range?
    Without sounding strange, both!

    The data validation is from a table column. I have created an INDIRECT reference in the data validation to point me back to the table that holds the drop down data (so the user can amend the list at another point in time without the need for my intervention)

    Thank you for your response

  6. #6
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,529

    Re: VBA to auto display drop down list when cell selected

    You can be column Specific

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Target.Column = 1 Then    ' this means column A
            Target.Application.SendKeys ("%{DOWN}")
        End If
    End Sub
    Or range specific

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Not Application.Intersect(Target, Me.Range("E13:J23")) Is Nothing Then
            Target.Application.SendKeys ("%{DOWN}")
        End If
    End Sub
    The code belongs in the worksheet module.

    RightClickTab.jpg

  7. #7
    Forum Contributor
    Join Date
    08-21-2012
    Location
    London
    MS-Off Ver
    Office 365 MAC
    Posts
    107

    Re: VBA to auto display drop down list when cell selected

    Quote Originally Posted by davesexcel View Post
    You can be column Specific

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Target.Column = 1 Then    ' this means column A
            Target.Application.SendKeys ("%{DOWN}")
        End If
    End Sub
    Or range specific

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        If Not Application.Intersect(Target, Me.Range("E13:J23")) Is Nothing Then
            Target.Application.SendKeys ("%{DOWN}")
        End If
    End Sub
    The code belongs in the worksheet module.

    Attachment 584255
    Thank you for responding. Unfortunately neither set of options works. I had found another piece of code with the ("%{DOWN}") reference and the code crashed at that point.

    Using your code had no effect when I click the cells... I must be doing something wrong!

  8. #8
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,529

    Re: VBA to auto display drop down list when cell selected

    I'll do a search, maybe there is a different sendkeys for mac.
    Last edited by davesexcel; 07-31-2018 at 02:18 PM.

  9. #9
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,529

    Re: VBA to auto display drop down list when cell selected

    Apologies, l I never knew send keys did not work for mac.

    If you search "excel sendkeys mac alternative" you could get some results, I can't test them out.

  10. #10
    Forum Contributor
    Join Date
    08-21-2012
    Location
    London
    MS-Off Ver
    Office 365 MAC
    Posts
    107

    Re: VBA to auto display drop down list when cell selected

    Quote Originally Posted by davesexcel View Post
    Apologies, l I never knew send keys did not work for mac.

    If you search "excel sendkeys mac alternative" you could get some results, I can't test them out.
    Thank you. Does that mean it will work for my Mac but not ofr PC users though?

  11. #11
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA to auto display drop down list when cell selected

    You could use a selection change macro to open a Userform

    Right Click on your sheet name at the bottom of excel and select view code

    Paste this code into the module that opens an then close it.

    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    With Target
    
    On Error GoTo Skip
    MyList = .Validation.Formula1
    
    UserForm1.Show
    
    End With
    Skip:
    On Error GoTo 0
    
    End Sub

    Create a Userform containing a list box

    Double click on the listbox to view its code/

    replace its code with

    
    Private Sub UserForm_Activate()
    MyArray = Split(ActiveCell.Validation.Formula1, ",")
    ListBox1.List = MyArray
    End Sub
    
    Private Sub ListBox1_Click()
    ActiveCell.Value = ListBox1.Value
    Unload Me
    End Sub
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    08-21-2012
    Location
    London
    MS-Off Ver
    Office 365 MAC
    Posts
    107

    Re: VBA to auto display drop down list when cell selected

    Thank you, that does indeed work, just takes time opening and closing, I do appreciate the effort though. There are literally hundreds of these dropdowns.

  13. #13
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA to auto display drop down list when cell selected

    This Ammended Code works for Lists and Ranges

    
    Private Sub UserForm_Activate()
    
    B = ActiveCell.Validation.Formula1
    T = ActiveCell.Validation.Formula2
    
    If T = "" Then
    
    Temp = ActiveCell.Validation.Formula1
    
    Else
    
    B = B * 1
    T = T * 1
    
    For Count = B To T
    Temp = Temp & Count & ","
    Next
    
    End If
    
    MyArray = Split(Temp, ",")
    ListBox1.List = MyArray
    
    End Sub
    Attached Files Attached Files

  14. #14
    Forum Contributor
    Join Date
    08-21-2012
    Location
    London
    MS-Off Ver
    Office 365 MAC
    Posts
    107

    Re: VBA to auto display drop down list when cell selected

    Thank you. I am grateful for all the responses

  15. #15
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: VBA to auto display drop down list when cell selected

    A Mash Up of Daves Solution and Mine


    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    On Error GoTo Skip
    B = ActiveCell.Validation.Formula1
    T = ActiveCell.Validation.Formula2
    
    If T <> "" Then
    
    B = B * 1
    T = T * 1
    
    For Count = B To T
    Temp = Temp & Count & ","
    Next
    
        With Selection.Validation
            .Delete
            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:=Temp
            .IgnoreBlank = True
            .InCellDropdown = True
            .InputTitle = ""
            .ErrorTitle = ""
            .InputMessage = ""
            .ErrorMessage = ""
            .ShowInput = True
            .ShowError = True
        End With
    End If
    
    ActiveCell.Application.SendKeys ("%{DOWN}")
    
    Skip:
    On Error GoTo 0
    
    End Sub

+ 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. Drop down list answer(s) selected to auto appear in another sheet
    By rcm4486 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-21-2017, 11:23 AM
  2. Drop down list answer(s) selected to auto appear in another sheet
    By rcm4486 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-21-2017, 10:49 AM
  3. Display selected columns in excel based on drop down list
    By tejboyd in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-21-2017, 09:23 AM
  4. Display multiple value when item selected in drop down list
    By peter.lu in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-15-2015, 05:06 PM
  5. Replies: 3
    Last Post: 01-28-2015, 01:09 AM
  6. How to display data based on a selected month from a drop-down list
    By Ahmed Ammar in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-14-2014, 09:24 PM
  7. VLOOKUP Function to display entire row of value selected via drop-down list
    By BamBamMoneyBags in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-08-2013, 03:00 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