使用全局字典保留动态值

时间:2018-12-01 10:57:37

标签: excel vba excel-vba

我在单元格B22中有一个If条件。它根据True的值返回FalseB1。单元格B1中的值是动态的。我在If中有另一个C22条件,如果N_50_C22参数为B22,则会调用函数True。我有一个要求,当单元格E1的参数仅在第一个开始变成C22时,我需要将B22的值复制到True中(通过上述函数)实例。 C22中此复制的值应保持不变,而与B22参数中的后续更改无关。

我具有下面的函数N_50_C22的VBA代码。

Public Dict_N_50_C22 As New Scripting.Dictionary

Public Function N_50_C22() As Double

    On Error GoTo ErrHandler:
    Dim High_Break_out As String, ReadCellValue As String

    If Not Dict_N_50_C22.Exists(High_Break_out) Then
        Dict_N_50_C22.Add High_Break_out, ""
    End If

    'Now retrieve the Order Status
    'This will return the value of Key Readcellvalue
    ReadCellValue = Dict_N_50_C22(High_Break_out)

    'If the order status equals the Trans then, we already placed order for that Trans
    'Exit the Function, don't place order again
     If ReadCellValue = "TRUE" Then
        Exit Function
    End If

    'If the Order Status is not equal to Trans then
    'Place the Order
    'Store the Trans as value to the Key TrdSym
    'So that next time it will return the Trans

    'Adding trans to dictionary key
    Dict_N_50_C22.Item(High_Break_out) = ThisWorkbook.Sheets("UP-MT").Range("B22").Value

    'Place the Order
    N_50_C22 = ThisWorkbook.Sheets("UP-MT").Range("E1").Value
Exit Function

ErrHandler:
    N_50_C22 = Err.Description
End Function

我遇到问题,该函数为B22的第一个true语句返回0值。您能解决这个问题吗?

IMG1

0 个答案:

没有答案