VBA code required to conclude average margin

exceluser9

Active Member
Joined
Jun 27, 2015
Messages
388
Hi Team,

I have below data in 2 sheets. I have week numbers in both the sheet. In sheet 1 i require the average margin in column "F" (Result column)

Based on the start week and end week it has to pull the average margin from sheet 2 for from whichever week falls between start week and end week based on the lookup from group id

I have just posted an example but there are multiple data in sheet 1 and 2

Sheet 1
Start dateStart weekEnd dateEnd weekGroup idResult
11/02/202220224906/03/2022202253X51AG57%
05/01/202220222818/01/2022202233XH7GY45%


Sheet 2
WeekGroup idMargin
202245X51AG56%
202249X51AG67%
202252X51AG44%
202254X51AG61%
202232XH7GY56%
202227XH7GY33%
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Is this the sort of thing you mean?
Not the same answers as you have but I'm assuming that is because you have not shown full data.
If this is not what you want then please give some sample data and expected results with sufficient information and explanation as to how you manually get the results.

22 04 14.xlsm
ABCDEF
1Sheet 1
2Start dateStart weekEnd dateEnd weekGroup idResult
311/02/20222022496/03/2022202253X51AG55.5%
45/01/202220222818/01/2022202233XH7GY56.0%
5
6
7Sheet 2
8WeekGroup idMargin
9202245X51AG56%
10202249X51AG67%
11202252X51AG44%
12202254X51AG61%
13202232XH7GY56%
14202227XH7GY33%
Average
Cell Formulas
RangeFormula
F3:F4F3=AVERAGEIFS(C$9:C$14,A$9:A$14,">="&B3,A$9:A$14,"<="&D3)
 
Upvote 0
Hi Peter,

I have checked the formula which you have provided. However, i do not see any validation against the group id. I have provided one more example below

Please could you provide validation for group id as well?

Sheet 1
Start dateStart weekEnd dateEnd weekGroup idResult
11/02/202220224906/03/2022202252X51AG40%
05/01/202220222818/01/2022202233XH7GY56%
13/01/2022202229
22/02/2011​
202231X51AG34%

WeekGroup idMargin
202245X51AG56%
202249X51AG36%
202252X51AG44%
202254X51AG61%
202232XH7GY56%
202227XH7GY33%
202229X51AG46%
202231X51AG22%
 
Upvote 0
However, i do not see any validation against the group id.
Yes, sorry, I missed that completely. :oops:

Try again

22 04 14.xlsm
ABCDEF
1Sheet 1
2Start dateStart weekEnd dateEnd weekGroup idResult
311/02/20222022496/03/2022202252X51AG40.0%
45/01/202220222818/01/2022202233XH7GY56.0%
513/01/202220222922/02/2011202231X51AG34.0%
6
7WeekGroup idMargin
8202245X51AG56%
9202249X51AG36%
10202252X51AG44%
11202254X51AG61%
12202232XH7GY56%
13202227XH7GY33%
14202229X51AG46%
15202231X51AG22%
Average (2)
Cell Formulas
RangeFormula
F3:F5F3=AVERAGEIFS(C$8:C$15,A$8:A$15,">="&B3,A$8:A$15,"<="&D3,B$8:B$15,E3)
 
Upvote 0

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,961
Latest member
nzskater

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