Total and Avg. data from another worksheet based on day of week
Closed
mikeexcelscrub
TrowaD
- Posts
- 1
- Registration date
- Monday June 16, 2014
- Status
- Member
- Last seen
- June 16, 2014
TrowaD
- Posts
- 2886
- Registration date
- Sunday September 12, 2010
- Status
- Moderator
- Last seen
- June 27, 2022
Related:
- Total and Avg. data from another worksheet based on day of week
- Macro to pull data from another worksheet based on criteria ✓ - Forum - Excel
- Populate separate worksheets with data from main worksheet based on criteria met ✓ - Forum - Excel
- Vba split data into multiple worksheets based on column ✓ - Forum - Excel
- Create worksheet based on lists & populate data from another... ✓ - Forum - Excel
- Which function can be used to directly bring automated data from one worksheet to another worksheet - Guide
1 reply
TrowaD
Jun 17, 2014 at 11:31 AM
- Posts
- 2886
- Registration date
- Sunday September 12, 2010
- Status
- Moderator
- Last seen
- June 27, 2022
Jun 17, 2014 at 11:31 AM
Hi Mike,
1) adding values based on day of the week.
* Select the cell you want to put the result in, run the code below.
* The code will ask you to input the day of the week.
* The code will give you the opportunity to cancel in case you forgot to select the correct destination cell.
Here is the code:
2) Obtaining average.
Use formula for that (assuming you placed result in A1 of sheet2):
=Sheet2!A1/COUNTIF(B2:B32,"MON")
Best regards,
Trowa
1) adding values based on day of the week.
* Select the cell you want to put the result in, run the code below.
* The code will ask you to input the day of the week.
* The code will give you the opportunity to cancel in case you forgot to select the correct destination cell.
Here is the code:
Sub RunMe() Dim lCol, MyCol As Integer Dim lRow, Result As Long Dim sValue As String Dim Check As Variant sValue = InputBox("For which day would you like to add the activities?:") Sheets("Sheet1").Select lRow = Range("B1").End(xlDown).Row For Each cell In Range("B2:B" & lRow) If cell.Value = sValue Then lCol = Cells(cell.Row, Columns.Count).End(xlToLeft).Column MyCol = 2 Do MyCol = MyCol + 1 Result = Result + Cells(cell.Row, MyCol).Value Loop Until lCol = MyCol End If Next cell Check = MsgBox("The result will be placed in the active cell.", vbOKCancel) If Check = vbCancel Then Exit Sub ActiveCell = Result End Sub
2) Obtaining average.
Use formula for that (assuming you placed result in A1 of sheet2):
=Sheet2!A1/COUNTIF(B2:B32,"MON")
Best regards,
Trowa