0

我有我的函数的代码:我在 j 中的函数的输出是列的位置。在函数内部,“i”查找与变量“tutor”和“mes”匹配的行的位置,然后给出单元格(i,j)的值。

单元格(ij)的值来自一张 excel 表的列表。列表的值为:“No cumple”、“Regular”、“Pleno”、“No se Considera”。该函数在内部将“No cumple”设为 0,将“Regular”设为 1,将“Pleno”设为 3,将“No se Considera”设为 0。

这些函数旨在计算函数的每个输入(“tutor”、“mes”、“j”)的值的平均值。

当“No se Considera”的情况在一个单元格中时,它意味着 if ,例如,有 5 个值必须计算平均值,“no se Considera”不考虑在内,所以函数只需要计算 4 个值的平均值。

问题是当 cell(ij) 的值为“No se Considera”时,该函数不起作用。

代码如下:

 Public Function mespt(tutor As String, mes As String, j As Long)
Application.Volatile

Dim a As Long
Dim totalmesp As Double


mespt = 0
contador = 0
totalmespt = 0
For i = 4 To 1000
If Sheets("Hoja1").Cells(i, 2).FormulaR1C1 = tutor And Sheets("Hoja1").Cells(i, 5).FormulaR1C1 = mes Then
Select Case Sheets("Hoja1").Cells(i, j).Value



Case "No cumple"
a = 0
Case "Regular"
a = 1
Case "Pleno"
a = 3
Case Else
contador = contador - 1
a = 0
End Select


totalmespt = totalmespt + a
contador = contador + 1
mespt = totalmespt / contador
End If
Next


End Function
4

2 回答 2

0
 Public Function mespt(tutor As String, mes As String, j As Long)
Application.Volatile

Dim a As Long
Dim totalmesp As Double


mespt = 0
contador = 0
totalmespt = 0
For i = 4 To 1000
If Sheets("Hoja1").Cells(i, 2).FormulaR1C1 = tutor And Sheets("Hoja1").Cells(i, 5).FormulaR1C1 = mes Then
Select Case Sheets("Hoja1").Cells(i, j).Value



Case "No cumple"
contador = contador + 1
a = 0
Case "Regular"
contador = contador + 1
a = 1
Case "Pleno"
contador = contador + 1
a = 3
Case Else
contador = contador - 1
a = 0
End Select


totalmespt = totalmespt + a
mespt = totalmespt / contador
End If
Next


End Function

这只是一个猜测,但我很确定这就是你要找的东西。

于 2013-10-09T17:58:45.297 回答
0
Public Function mespt(ByVal tutor As String, ByVal mes As String, ByVal j As Long) As Double

    Dim totalmespt As Double
    Dim contador As Long
    Dim i As Long

    With Sheets("Hoja1")
        For i = 4 To 1000
            If .Cells(i, "B").Value & .Cells(i, "E").Value = tutor & mes _
            And InStr(1, "|no cumple|regular|pleno|", "|" & .Cells(i, j).Value & "|", vbTextCompare) > 0 Then
                contador = contador + 1
                totalmespt = totalmespt + WorksheetFunction.Match(.Cells(i, j).Value, Array("no cumple", "regular", "", "pleno"), 0) - 1
            End If
        Next i
    End With

    If contador > 0 Then mespt = totalmespt / contador Else mespt = 0

End Function
于 2013-10-09T18:48:55.597 回答