Results 1 to 4 of 4

Thread: VBA: Counting an "if" loop to get average.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Post VBA: Counting an "if" loop to get average.

    Hi im learning how to program in VBA and i have a problem with this code...
    I need to count the even number of X random Cells then have to do an average of this numbers. My problem is, how count all even numbers to divide it by the sum of all.


    Here is my code....

    Sub Numbers()
    Dim row, op, add As Integer
    row = 1
    For coun = 1 To 5
    op = Cells(row, 1).Value Mod 2
    If op = 1 Then
    add = Cells(row, 1).Value + next
    ElseIf op = 0 Then
    addim = Cells(row, 1).Value + next2
    End If
    next2 = addim
    next = add
    row = row + 1
    avg = addim / **** < Here is my problem, how can i count all the even numbers in the loop to divide by, in the expresion?
    Next
    Range("C1").Value = add
    Range("D1").Value = avg
    End Sub

    Thanks in advance
    Last edited by Aussiebear; 03-24-2019 at 07:06 PM. Reason: Added code tags to submitted code

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •