View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default Summerizing 35 codes in one

You can pass an object as an argument to function/sub:
Function MatchCombo(argCombo As ComboBox) As Variant
'add error trap for unMatched values
With argCombo
MatchCombo= Application.WorksheetFunction.Match(.Value, [D2:D6], 0)
End With
End Function

Private Sub ComboBox1_Change()
Dim RetVal as Long
RetVal = MatchCombo(ComboBox1)
'Check for a valid return value.
'...etc
Exit Sub

NickHK

"LoveCandle" wrote
in message ...

Hi everybody,

I have the following code which is implemented on 35 comboboxes in one
sheet .. I wrote the same code 35 times .. only changing the comboxbox
number.

Can I implement the same code on 35 comboboxes without repeating it 35
times?


Code:
--------------------
Private Sub ComboBox1_Change()
On Error GoTo X
ComboBox1 = Application.WorksheetFunction.Match(ComboBox1, [D2:D6], 0)
Exit Sub
X:
If Err = 1004 Then
Me.Activate
Else
Resume
End If
End Sub
--------------------


I hope that my question is clear for all,

Thank you,


--
LoveCandle
------------------------------------------------------------------------
LoveCandle's Profile:

http://www.excelforum.com/member.php...o&userid=28612
View this thread: http://www.excelforum.com/showthread...hreadid=564205