Results 1 to 4 of 4

Thread: Excel VBA/Listbox Query

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2004
    Location
    Right here
    Posts
    275

    Excel VBA/Listbox Query

    Hi,

    I have an ActiveX Listbox located in an Excel worksheet and I am using it as a way to allow the user to select an item from the listbox and then there is a table next to this which some VBA code copies different data into depending on what item is selected in the list box.

    The user can then edit the current data in the table by simply selecting the relevant cell(s) and then manually entering new text or figures.

    The problem I am having is that if the user changes the data in the table and the doesn't press Enter/Return before selecting another item in the listbox, the code associated with the listbox doesn't run.

    I would guess that the focus is still on the active cell because Enter/Return has not been pressed. Is there any VBA code that I can use that will get around this? I was thinking of something like "GetFocus" to put the focus back on the listbox when an item is selected from it but I can't get this to work.

    Anyone here have any ideas?

    Thanks
    -Rob
    http://www.sudsolutions.com

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Excel VBA/Listbox Query

    Maybe you can send an Escape keypress to cancel the edit mode of the cell in the ListBox1_GotFocus event.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2004
    Location
    Right here
    Posts
    275

    Re: Excel VBA/Listbox Query

    That might work.

    Um, how do I do that then?

    Cheers
    -Rob
    http://www.sudsolutions.com

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Excel VBA/Listbox Query

    Try the basic SendKeys. It is supported in VBA.
    VB Code:
    1. SendKeys "{ESC}"
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width