Excel错误424需要帮助

时间:2017-03-02 20:22:18

标签: excel vba excel-vba

我无法弄清楚为什么Excel不喜欢这段代码,而且我已经介绍了我(尽管)有关如何排除故障的所有有限知识。

我的代码调用我在网上发现的ProperUnion代码,该代码应该处理空范围和重复。我只是基本掌握了第二位代码是如何工作的。第一位都是我的。

此代码根据是否标记项目选择项目列表,将每个标记保存为范围,然后根据需要将它们相交。在我只测试" Flag 3"检查框可能是导致问题的原因。 (所以rngx(1)rngx(2)rngx(4)+都是空值。)

我把' xxxxxxx放在Proper union的行上,它给了我调试错误。

非常感谢任何和所有帮助。

收集已标记的信息代码

  Function ProperUnion(ParamArray Ranges() As Variant) As Range
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' ProperUnion
    ' This provides Union functionality without duplicating
    ' cells when ranges overlap. Requires the Union2 function.
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Dim ResR As Range
        Dim n As Long
        Dim r As Range

        If Not Ranges(LBound(Ranges)) Is Nothing Then 'xxxxxxxxxx
            Set ResR = Ranges(LBound(Ranges))
        End If
        For n = LBound(Ranges) + 1 To UBound(Ranges)
            If Not Ranges(n) Is Nothing Then
                For Each r In Ranges(n).Cells
                    If Application.Intersect(ResR, r) Is Nothing Then
                        Set ResR = Union2(ResR, r)
                    End If
                Next r
            End If
        Next n
        Set ProperUnion = ResR
    End Function
'Union2 is required for ProperUnion

Function Union2(ParamArray Ranges() As Variant) As Range
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Union2
    ' A Union operation that accepts parameters that are Nothing.
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Dim n As Long
        Dim RR As Range
        For n = LBound(Ranges) To UBound(Ranges)
            If IsObject(Ranges(n)) Then
                If Not Ranges(n) Is Nothing Then
                    If TypeOf Ranges(n) Is Excel.Range Then
                        If Not RR Is Nothing Then
                            Set RR = Application.Union(RR, Ranges(n))
                        Else
                            Set RR = Ranges(n)
                        End If
                    End If
                End If
            End If
        Next n
        Set Union2 = RR
    End Function

适当的联盟代码 来自:http://www.cpearson.com/Excel/BetterUnion.aspx

$sql = "SELECT nickname, items, data, time FROM user{$iduser}";
$result = $conn->query($sql);
while (null !== ($row = $result->fetch_assoc())) {
    $nickname = openssl_decrypt(
        base64_decode($row['nickname']),
        $encrypt_method,
        $key2crypt,
        0,
        $iv
    );

    $items = openssl_decrypt(
        base64_decode($row['items']),
        $encrypt_method,
        $key2crypt,
        0,
        $iv
    );

    $data = openssl_decrypt(
        base64_decode($row['data']),
        $encrypt_method,
        $key2crypt,
        0,
        $iv
    );

    $time = openssl_decrypt(
        base64_decode($row['time']),
        $encrypt_method,
        $key2crypt,
        0,
        $iv
    );

    echo "{$nickname},{$items},{$data},{$time}\n";
}

1 个答案:

答案 0 :(得分:1)

您已将rngx声明为Variant数组,但应将其声明为Range个对象的数组。

所以将声明改为:

Dim rngx(1 To 8) As Range

按照目前的说法,rngx的未分配元素将传递给ProperUnion,类型为Variant/Empty,这就是崩溃的原因。通过将rngx更改为Range,参数将作为Variant/Range传递,未分配的元素为Nothing