Count & Sum Data

Panoos64

Well-known Member
Joined
Mar 1, 2014
Messages
890
Hi to everyone, i would to create a vba code so that to count the col "A" by "Terms of Stay" and "SUM in col. "B" for each type its accommodation as my below example. In schedule 1. are the original data and in schedule 2. is the expected result.

Many thanks in advance

Schedule 1.

A/P
A/P
A/P
B/B
B/B
H/B
H/B
H/B
H/B
H/B
H/B
O/T
O/T

<colgroup><col style="mso-width-source:userset;mso-width-alt:3474;width:71pt" width="95"> <col style="mso-width-source:userset;mso-width-alt:3949;width:81pt" width="108"> </colgroup><tbody>
[TD="width: 95"]Terms Stay[/TD]
[TD="width: 108"]Accomodation[/TD]

[TD="align: right"]1262[/TD]

[TD="align: right"]342[/TD]

[TD="align: right"]1400[/TD]

[TD="align: right"]855[/TD]

[TD="align: right"]957[/TD]

[TD="align: right"]1262[/TD]

[TD="align: right"]2304[/TD]

[TD="align: right"]342[/TD]

[TD="align: right"]1970[/TD]

[TD="align: right"]546[/TD]

[TD="align: right"]1274[/TD]

[TD="align: right"]1945[/TD]

[TD="align: right"]2025[/TD]

</tbody>



Schedule 2.


<colgroup><col style="mso-width-source:userset;mso-width-alt:3474;width:71pt" width="95"> <col style="mso-width-source:userset;mso-width-alt:3949;width:81pt" width="108"> </colgroup><tbody>
[TD="width: 95"]Terms Stay[/TD]
[TD="width: 108"]Accomodation[/TD]

[TD="class: xl65"]A/P 3 RMS[/TD]
[TD="align: right"]3004[/TD]

[TD="class: xl65"]B/B 2 RMS[/TD]
[TD="align: right"]1812[/TD]

[TD="class: xl65"]H/B 6 RMS[/TD]
[TD="align: right"]7698[/TD]

[TD="class: xl65"]O/T 2 RMS[/TD]
[TD="align: right"]3970[/TD]

</tbody>
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try
=SUMIF($A$3:$A$15,LEFT(D3,3),$B$3:$B$15)


Book1
ABCDE
1Schedule 1.Schedule 2.
2Terms StayAccomodationTerms StayAccomodation
3A/P1262A/P 3 RMS3004
4A/P342B/B 2 RMS1812
5A/P1400H/B 6 RMS7698
6B/B855O/T 2 RMS3970
7B/B957
8H/B1262
9H/B2304
10H/B342
11H/B1970
12H/B546
13H/B1274
14O/T1945
15O/T2025
Sheet1
Cell Formulas
RangeFormula
E3=SUMIF($A$3:$A$15,LEFT(D3,3),$B$3:$B$15)
E4=SUMIF($A$3:$A$15,LEFT(D4,3),$B$3:$B$15)
E5=SUMIF($A$3:$A$15,LEFT(D5,3),$B$3:$B$15)
E6=SUMIF($A$3:$A$15,LEFT(D6,3),$B$3:$B$15)
 
Upvote 0
Hi Jonmo, the formula is right but it appears result (0) zero. However thanks for your support and your time spent for my project. Is there any VBA code? I think is going to be easier through VBA. Thanks again
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,307
Members
452,633
Latest member
DougMo

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