Ok, Eric, here goes... first I must set the conditions under which this will
work.
The drop down boxes must be one from the Excel "Control Toolbox", not from
the "Forms" tools.
To work properly the drop down boxes must have their Linked Cell set to a
cell on the worksheet. Right click on each one and choose [Properties] to
set the source of its list (ListFillRange property) and the Linked Cell.
Here is the revised code that works under these restrictions:
Public Function ComboCountWithData() As Integer
Dim intCount As Integer
Dim objTemp As Object
Application.Volatile
intCount = 0
For Each objTemp In ActiveSheet.OLEObjects
If TypeOf objTemp.Object Is MSForms.ComboBox Then
If objTemp.Object.Value <> "" Then
intCount = intCount + 1
End If
End If
Next
ComboCountWithData = intCount
End Function
To put the code into your workbook, open it up. Press [Alt]+[F11] to open
the VB editor. Since you probably already have a module in it with the older
code, just choose that module and replace the code in it with the code above.
Each
Eric said:
Thank everyone very much for suggestions
Could you please tell me how to call this function?
When the 4 comboboxs are selected, and insert ComboCountWithData() into cell
A1, it returns 0. Could you please tell me how to call this function?
Thank everyone very much for any suggestions
Eric