1

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

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.