0% found this document useful (0 votes)
30 views

Code

This macro takes the values in a specified range of cells that are greater than or equal to a threshold value, sums them, counts them, and calculates the average. It initializes variables for the threshold, summation, and count. It then loops through the range, summing values above the threshold and counting them, before computing the average and outputting it to a cell.

Uploaded by

Collin Turbert
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views

Code

This macro takes the values in a specified range of cells that are greater than or equal to a threshold value, sums them, counts them, and calculates the average. It initializes variables for the threshold, summation, and count. It then loops through the range, summing values above the threshold and counting them, before computing the average and outputting it to a cell.

Uploaded by

Collin Turbert
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

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

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

You might also like