Count string of text in combobox

MFish

Board Regular
Joined
May 9, 2019
Messages
76
Hi,

I need a combobox_Change() code that will update my textbox1 that when I make ANY selection in my combobox, it will add "+1" to my textbox.

Events -

I select a combobox selection in cmb1 and in textbox1 it just says "1".
I select another combobox selection in cmb2 and in textbox 1 it now says "2".
On the same note, if I have to delete the selection in cmb2 the textbox should update back to "1".

I have 30 comboboxes I need this to do to textbox1.

If it matters, I only have Capital Letters in my combobox list. No numbers at all.

I'm hoping this is a relatively simple code. Thanks.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Try this:

Code:
Private Sub ComboBox1_Change()
    If ComboBox1.ListIndex > -1 Then
        TextBox1.Value = Val(TextBox1) + 1
    ElseIf ComboBox1.Value = "" Then TextBox1.Value = Val(TextBox1) - 1
    End If
End Sub
 
Upvote 0
Try this:

Code:
Private Sub ComboBox1_Change()
    If ComboBox1.ListIndex > -1 Then
        TextBox1.Value = Val(TextBox1) + 1
    ElseIf ComboBox1.Value = "" Then TextBox1.Value = Val(TextBox1) - 1
    End If
End Sub

Hi DanteAmor,

This works decent. It will count by 1 whenever I make a selection... Problem is... If I accidentally click on the wrong selection in Combobox1 and must change my answer, the textbox will now go to "2", when I still am working on Combobox1 selection. Does that make sense?
 
Upvote 0
Hi DanteAmor,

This works decent. It will count by 1 whenever I make a selection... Problem is... If I accidentally click on the wrong selection in Combobox1 and must change my answer, the textbox will now go to "2", when I still am working on Combobox1 selection. Does that make sense?


Try this

Code:
Private Sub ComboBox1_Change()
    Call [COLOR=#0000ff]Counter_Combos[/COLOR]
End Sub
Private Sub ComboBox2_Change()
    Call [COLOR=#0000ff]Counter_Combos[/COLOR]
End Sub
Private Sub ComboBox3_Change()
    Call [COLOR=#0000ff]Counter_Combos[/COLOR]
End Sub


Sub [COLOR=#0000ff]Counter_Combos[/COLOR]()
    Dim ctrl As Control
    TextBox1 = ""
    For Each ctrl In Controls
        If TypeName(ctrl) = "ComboBox" Then
            If ctrl.ListIndex > -1 Then
                TextBox1 = Val(TextBox1.Value) + 1
            End If
        End If
    Next
End Sub
 
Upvote 0
Try this

Code:
Private Sub ComboBox1_Change()
    Call [COLOR=#0000ff]Counter_Combos[/COLOR]
End Sub
Private Sub ComboBox2_Change()
    Call [COLOR=#0000ff]Counter_Combos[/COLOR]
End Sub
Private Sub ComboBox3_Change()
    Call [COLOR=#0000ff]Counter_Combos[/COLOR]
End Sub


Sub [COLOR=#0000ff]Counter_Combos[/COLOR]()
    Dim ctrl As Control
    TextBox1 = ""
    For Each ctrl In Controls
        If TypeName(ctrl) = "ComboBox" Then
            If ctrl.ListIndex > -1 Then
                TextBox1 = Val(TextBox1.Value) + 1
            End If
        End If
    Next
End Sub

Once I change the Textbox1 to the unique ID and try to run the code, it gives me a runtime error. Highlights txttotalpallet = "" and says it has no variable.
 
Upvote 0
Once I change the Textbox1 to the unique ID and try to run the code, it gives me a runtime error. Highlights txttotalpallet = "" and says it has no variable.


What is txttotalpallet? Is it a textbox?


You can put your code updated.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top