1,105,333 Community Members

VBA Check Combo Value

Member Avatar
ImZick
Posting Whiz in Training
201 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 4 [?]
 
0
 

Im using VBA build inside excel
is there a way to find if ComboBox has a value?
for example
i have 80 ComboBox and i want to check if they have a value like "A", "B", "C" and "D"
and if the value is blank like "" then stop the checking.

Member Avatar
ImZick
Posting Whiz in Training
201 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 4 [?]
 
0
 

Im thinking something like this
but surely it doesn't work

Public Sub Test()
Dim ComboBox As String
Dim i As Long

    For i = 1 To 80 
        If ComboBox & i.Text = "Level 4" Then
            Range("S8") = "0.12"
        End If
    Next

End Sub

Member Avatar
AndreRet
Industrious Poster
4,492 posts since Jan 2008
Reputation Points: 362 [?]
Q&As Helped to Solve: 499 [?]
Skill Endorsements: 24 [?]
 
0
 

You are almost on the right track. :) Try the following...

Public Sub Test()
Dim cmbMyBox As ComboBox ''Do Not use ComboBox, it is a reserved name for ... combobox

Dim i As Integer
    For i = 1 To 80 
        If cmbMyBox(i).Text = "Level 4" Then ''Assuming that you have an array of 80 combo's
            Range("S8") = "0.12"
        Elseif cmbMyBox(i).Text = "" Then
            Exit Sub ''Exit and do something...
        End If
    Next
End Sub
Member Avatar
ImZick
Posting Whiz in Training
201 posts since Dec 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 4 [?]
 
0
 

I got an error
Object variable or With block variable not set

and it highlight this code

        If cmbMyBox(i).Text = "Level 4" Then ''Assuming that you have an array of 80 combo's
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: