Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Switch Argument = Field

Status
Not open for further replies.

onlyleif

Industrial
Dec 3, 2007
1
I am working on a switch function that checks the value in some fields and depending on the current value, it prints a new value.

Code:
Start Sub
field = Range("L14")
ActiveCell.FormulaR1C1 = Tålamod(field)
End Sub

Function Tålamod(Resultat As Integer)
    Tålamod = Switch(Resultat = "9", "70", Resultat = "10", "73", Resultat = "11", "76", Resultat = "12", "79", Resultat = "13", "82", Resultat = "14", "85", Resultat = "15", "88", Resultat = "16", "92", Resultat = "17", "95", Resultat = "18", "98")
End Function
I hope that this shows what I am trying to accomplish.
The problem here is getting the function to excecute with a field of my choice as the argument.
If this is not possible, then if saving the value from a specific field into a variable and use the variable instead.
 
Replies continue below

Recommended for you

I don't have excel on my machine so this is written in VBScript - similar but you have to add decls for excel. Try this
Code:
Function xxx(Resultat)
    const ixcmp = 0, ixval=1, ixmax=2
    dim lut, ix
    lut = array ("9", "70", "10", "73", "11", "76", "12", "79", "13", "82", "14", "85", "15", "88", "16", "92", "17", "95", "18", "98")
    for ix = 0 to ubound(lut) step ixmax
       if Resultat = lut(ix + ixcmp) then
          xxx = lut(ix + ixval)
          exit for
       end if
    next
End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor