3

Hi im new using excel and i would like to count the cell that containg the values betweeen 500 and 750. this is the code that i wrote but i did something wrong that is not giving me the right answer. Can some one please help?

Sub Count()
    Dim i As Integer
    Dim j As Integer

    Range("C3").Select

    For i = 1 To 279
        For j = 1 To 19
            If i > 500 Then
            ElseIf i <= 750 Then
                i = i + 1
            End If
        Next j
    Next i

    Sheets("Sheet1").Select
    Range("B13").Select
    ActiveCell.Value = i
End Sub
4

2 に答える 2

0

少し調整するだけでコードが機能します。

Sub count()
    Dim i As Integer
    Dim j As Integer
    Dim countCell As Integer

    Range("C3").Select

    For i = 1 To 279
        For j = 1 To 19
            If Cells(i, j).Value >= 500 And Cells(i, j).Value <= 750 Then
                countCell = countCell + 1
            End If
        Next
    Next

    MsgBox countCell & " Cells Found", vbInformation

    Sheets("Sheet1").Select
    Range("B13").Select
    ActiveCell.Value = i
End Sub
于 2013-05-16T03:31:15.410 に答える