Call VBA function that returns custom type from spreadsheet

后端 未结 2 1370
南旧
南旧 2021-01-22 23:22

I have a vba function that returns a custom data type, defined as:

Public Type stockValue
        stock As String
        value As Double
End Type
相关标签:
2条回答
  • 2021-01-22 23:43

    You can only return data types that Excel understands from a user-defined function. Excel does not understand custom data types.

    Instead you would have to return a variant array containing the 2 values from your custom data type. Then either you would array enter the function into 2 cells, or use another function such as INDEX to retrieve the value you wanted from the returned array.

    0 讨论(0)
  • 2021-01-23 00:04

    You can do the following :

    Type XYDouble
        X As Double
        Y As Double
    End Type
    
    Private Function Compute(ByVal X As Double, ByVal Y As Double) As XYDouble
        Compute.X = ....
        Compute.Y = ...
    End Function
    
    
    Function ComputeX(ByVal X As Double, ByVal Y As Double) As Double
        ComputeX = Compute(X, Y).X
    End Function
    
    Function ComputeY(ByVal X As Double, ByVal Y As Double) As Double
        ComputeY = Compute(X, Y).Y
    End Function
    

    and, you can get the X (or Y) value in cell with the formula : "=ComputeX(C7;D7)"

    0 讨论(0)
提交回复
热议问题