vba函数我想移植到libreoffice

时间:2014-08-01 03:56:56

标签: vba

此功能在excel中工作,但是当我尝试将其移植到libreoffice时,它不起作用(vba标准已更改?)

variant()显然不是openoffice中的数据类型......

但这是我的代码

Public Function RankECDF(ByRef r_values As Range) As Variant()

Dim N As Integer, M As Integer

Dim total As Integer

Dim y() As Variant

N = r_values.Rows.Count
M = r_values.Columns.Count

y = r_values.Value    'copy values from sheet into an array

Dim V() As Variant
ReDim V(1 To N, 1 To M)

    total = WorksheetFunction.Sum(r_values)

            For R = 1 To N
                For C = 1 To M

                    If y(R, C) = "" Then

                    V(R, C) = ""

                    Else

                        'would error if cell was ""

                        V(R, C) = WorksheetFunction.Average(WorksheetFunction.Rank(y(R, C), r_values, 1), WorksheetFunction.CountIf(r_values, "<=" & y(R, C))) / WorksheetFunction.Count(r_values)

                    End If

                 Next C
            Next R

RankECDF = V

End Function

1 个答案:

答案 0 :(得分:1)

是的,OpenOffice不喜欢Variant(),但这应该没问题,因为Variant可以做任何事情,即使是Variant()对吗?

在v4.0下,将代码插入OpenOffice的基本调试程序(工具 - &gt;宏 - &gt; OrganizeMacros - &gt; OpenOffice Basic ... )并打开{{ 1}}显示以下内容:

enter image description here

所以看起来N = r_values.Rows.Count不是r_values而是Range

当我更改代码以处理Variant()时(使用r_values),它似乎有效。试试这个:

UBound