Reputation: 99
My code below works in Excel VBA however i am changing to VB userform. The problem is i cant use OLEObjects anymore so is there a workaround in VB to have this work for me in a userform? or do i need to put this in a long if statement. Thanks in advance.
Dim Fun As Variant
Dim Tmp As Variant
Dim Inv() As String
Dim i As Integer
Inv = Split("NBInv NEBInv EBInv SEBInv SBInv SWBInv WBInv NWBInv")
Fun = 0
For i = 0 To UBound(Inv)
Tmp = Val(MainForm.OLEObjects(Inv(i)).Object.Value)
If Tmp <> 0 And Tmp <> "" And Tmp > Fun Then Fun = Tmp
Next i
Smallest = Fun
MsgBox Smallest
Upvotes: 1
Views: 213
Reputation: 4363
On the assumption that these are control names on your userform:
Dim Fun As Variant
Dim Tmp As Variant
Dim Inv() As String
Dim i As Integer
Inv = Split("NBInv NEBInv EBInv SEBInv SBInv SWBInv WBInv NWBInv")
Fun = 0
For i = 0 To UBound(Inv)
Tmp = Val(Me.Controls(Inv(i)).Value)
If Tmp <> 0 And Tmp <> "" And Tmp > Fun Then Fun = Tmp
Next i
Smallest = Fun
MsgBox Smallest
Upvotes: 1