0

所以我以为我的任务是一个非常简单的目标,但事实证明我正在为此苦苦挣扎。

我有一段非常简单的代码要执行,is numeric 函数背后的想法意味着它会跳过非数字单元格,只将数值放入计算中。伟大的。但是,我希望它将长度变量扩展 1,以便对于每个空白,它会添加一个额外的数字以保持 Length 的真实值相同。

但是我不能让它工作。我的数字函数似乎什么都不做。

有人可以帮忙吗?

    Function RSE(MyCells As Range, Length As Double)  
    Dim up_day, down_day, ups, downs
    Dim average_up, average_down
    Dim rs, cellcount, rangecount As Long
    Dim cll As Range
    ups = 0
    up_day = 0
    downs = 0
    down_day = 0
    cellcount = 0
    rangecount = 0

For Each cll In MyCells


    If IsNumeric(cll) Then

    cellcount = cellcount + 1
    If cellcount = Length Then Exit For
    If cll.Value >= cll.Offset(1, 0).Value Then
    downs = downs + cll - cll.Offset(1, 0).Value
    ElseIf cll.Value < cll.Offset(1, 0).Value Then
    ups = ups + cll.Offset(1, 0).Value - cll.Value
    End If

    Else:

    Length = Length + 1

    End If

    Next cll
    average_up = ups / Length
    average_down = downs / Length

    rs = average_up / average_down

    RSE = 100 - (100 / (1 + rs))



    End Function
4

1 回答 1

1

你应该使用

If IsNumeric(cll) And Not isEmpty(cll) Then

因为一个空单元格被认为是一个数值


重新编辑

这就是我将如何做到的

Function RSE(MyCells As Range, Length As Double)
    Dim up_day, down_day, ups, downs
    Dim average_up, average_down
    Dim rs, cellcount, rangecount As Long
    Dim cll As Range
    Dim nbBlank As Integer
    ups = 0
    up_day = 0
    downs = 0
    down_day = 0
    cellcount = 0
    rangecount = 0

For Each cll In MyCells

    If cll.Address <> MyCells.Cells(1, 1).Address Then 'skip first address
        If IsNumeric(cll) And Not IsEmpty(cll) Then

        cellcount = cellcount + 1
        If cellcount = Length Then Exit For
        If cll.Offset(-1 - nbBlank, 0).Value >= cll.Value Then
        downs = downs - cll + cll.Offset(-1 - nbBlank, 0).Value
        ElseIf cll.Offset(-1 - nbBlank, 0).Value < cll.Value Then
        ups = ups - cll.Offset(-1 - nbBlank, 0).Value + cll.Value
        End If
        nbBlank = 0

        Else:

        nbBlank = nbBlank + 1

        End If
    End If
    Next cll
    average_up = ups / Length
    average_down = downs / Length

    rs = average_up / average_down

    RSE = 100 - (100 / (1 + rs))

    End Function
于 2014-04-29T11:35:13.773 回答