We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,580 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

VBA Check Combo Value

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.

2
Contributors
3
Replies
5 Hours
Discussion Span
4 Months Ago
Last Updated
5
Views
Zick Technology
Junior Poster
183 posts since Dec 2012
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 3

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

Zick Technology
Junior Poster
183 posts since Dec 2012
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 3

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
AndreRet
Industrious Poster
4,706 posts since Jan 2008
Reputation Points: 391
Solved Threads: 481
Skill Endorsements: 20

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
Zick Technology
Junior Poster
183 posts since Dec 2012
Reputation Points: 0
Solved Threads: 2
Skill Endorsements: 3

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0625 seconds using 2.65MB