Sub AvgX() ' This macro put all the values that are >= the threshold value ' in the cell

on the code page ' Set the sheet to begin the macro Sheets("Code").Select ' Initialize variables threshold = Range("C7").Value sum_val = 0 cnt_val = 0 rctr = 1 'Loop over all the values and sum and count them Do Until Cells(rctr, 1).Value = "" ' Find and output all values >= threshold x = Cells(rctr, 1).Value If x >= threshold Then 'Update the summation sum_val = sum_val + x 'Update the count cnt_val = cnt_val + 1 End If Next 'Update the row counter rctr = rctr + 1 Loop 'Compute the average
Comment [.1]: Instead of using the do until command just tell it what rows to look at, ie. Specify the range for rctr

Value = avg_valsum_val / cnt_val End Sub .avg_val = sum_val / cnt_val 'Output the average Range("E8").

Sign up to vote on this title
UsefulNot useful