|
-
Jun 23rd, 2008, 06:40 AM
#1
Thread Starter
New Member
[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.
-
Jun 23rd, 2008, 05:00 PM
#2
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
-
Jun 23rd, 2008, 06:07 PM
#3
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.
-
Jun 24th, 2008, 12:43 PM
#4
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|