Results 1 to 4 of 4

Thread: [RESOLVED] Move to next item in ActiveX combobox on excel worksheet

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    12

    Resolved [RESOLVED] Move to next item in ActiveX combobox on excel worksheet

    Hi there,

    I have an ActiveX combobox on a worksheet populated from one column of cells on that worksheet. I have i set up if the first item is selected a form will open to allow the user to enter customised values. The other selections are all preset. The other option on the form is a check box to save this data.

    The trigger for the userform is Private Sub CboxCircuit_Change()
    ie. A change to the combobox

    The problem I have is when I try to save these new values, the cells I am saving to are referenced to the combobox. So when I paste the data to these cells, it treats it as a combobox_change, and because my current value in the combobox is still set to the first item, which triggers the form to open, I end up in a loop, with the form opening again.

    The solution, I believe, is to change the combobox value to the next item in the list and then run my save procedure.

    My question is...how do I do this?
    I have tried
    CboxCircuit.value = Sheet1.Range("J7").Value 'the next item in the list (run-error '424')
    CboxCircuit.ListIndex = CboxCircuit.ListIndex + 1 (same error)

    Is there a .offset property I can use?

    Any help would be greatly appreciated.

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Move to next item in ActiveX combobox on excel worksheet

    if the code is in the forms code page you would need to specify the sheet the cboxcircuit is on
    sheets("mysheet").cboxcircuit......
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    Re: Move to next item in ActiveX combobox on excel worksheet

    I couldn't find a better way, but you can use a flag to find out how the LinkedCell and then the CBox have been changed.

    Code on Sheet1 that contains the combobox:
    Code:
    Option Explicit
    
    Dim bFocusOnCboxCircuit As Boolean
    
    Private Sub CboxCircuit_GotFocus()
        bFocusOnCboxCircuit = True
    End Sub
    
    Private Sub CboxCircuit_LostFocus()
        bFocusOnCboxCircuit = False
    End Sub
    
    Private Sub CboxCircuit_Change()
        If bFocusOnCboxCircuit = True Then
            If CboxCircuit.ListIndex = 0 Then
                UserForm1.Show
            End If
        End If
    End Sub
    *Notes: Make sure the combobox has no focus at the beginning when bFocusOnCboxCircuit = False by selecting a cell.
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  4. #4

    Thread Starter
    New Member
    Join Date
    Apr 2008
    Posts
    12

    Re: Move to next item in ActiveX combobox on excel worksheet

    Thanks for the help. Westconn's suggestion to include the sheet name that the combo box is on worked.

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