Averaging values in a column with conditions in two other columns

DPECK

New Member
Joined
Sep 4, 2014
Messages
31
I have a 57 column, 8832 row spread sheet that I'm extracting data from and creating tables and charts. I'm wanting to calculate the average number of days it took to complete each work order. I have a column with the "days to complete" (col AE) and the conditions that I want to meet are status (col H) = Comp and CrewId (this will change with the crew. Elect, I&C, FireSys... )(col AH). How do I write the VBA code for this?
 
bbott,
I modified the sheet and range references to the workbook that the data is in and tried the code. It runs until the 1st For loop and locks up. I tried all that I know and can't get it to work. Thanks for your efforts.


Sub CrewAve() Dim x As Long Application.ScreenUpdating = False Sheets.Add after:=Sheets(Sheets.Count) ActiveSheet.Name = "Crew Averages" Range("A1") = "Crew ID" Range("B1") = "Average Days" For x = 2 To Sheets(1).Range("H" & Rows.Count).End(xlUp).Row If Sheets(1).Range("H" & x) <> Sheets(1).Range("H" & x).Offset(-1, 0) Then Range("A" & Range("A" & Rows.Count).End(xlUp).Row).Offset(1, 0) = Sheets(1).Range("H" & x) End If Next x For x = 2 To Range("A" & Rows.Count).End(xlUp).Row Range("B" & x) = WorksheetFunction.AverageIfs(Sheets(1).Range("F:F"), _ Sheets(1).Range("H:H"), Range("A" & x), _ Sheets(1).Range("C:C"), "Comp", _ Sheets(1).Range("B:B"), "<>PM", _ Sheets(1).Range("B:B"), "<>PdM") Next x Columns("A:B").AutoFit Application.ScreenUpdating = True End Sub</pre>
 
Last edited:
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

Forum statistics

Threads
1,224,899
Messages
6,181,627
Members
453,058
Latest member
rmd0725

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top