Looping through range and get average

خرید بک لینک

I'm looping through a range of cells and checking each cell for condition requirement. Seems like it's not catch each cell's value. Only retuing the first cell value. I'm trying to get the average of the range at the same time checking conditions.

Sub test()

    Dim NEWSTRING As String
    Dim OLDSTRING As String
    Dim tem As String
    Dim tempFirstVal As String
    Dim Avg As String

    For Each c In Worksheets("Sheet1").Range("a1:a5").Cells

        If InStr(c.Value, "+") Then

            OLDSTRING = c.Value
            NEWSTRING = Left(OLDSTRING, Len(OLDSTRING) - 1)

            tem = CInt(NEWSTRING)
            tempFirstVal = tem
            checkValGreaterThanSixty (tempFirstVal)
            If tempFirstVal > 20 Then
                Exit Sub
            ElseIf firstVal < 20 And InStr(firstVal, "+") Then
                MsgBox ("This is not allowed")
                Exit Sub
            End If
        Else
            checkValGreaterThanSixty (tempFirstVal)
            If tempFirstVal > 20 Then
                Exit Sub
            End If
        End If
    Next

    Avg = Application.WorksheetFunction.Average(tempFirstVal)
    Range("D1011").Value = Avg

End Sub

Recent Questions...

ما را در سایت Recent Questions دنبال می‌کنید

برچسب: نویسنده: استخدام کار بازدید: 174 تاريخ: سه شنبه 21 ارديبهشت 1395 ساعت: 1:50

صفحه بندی