Count & Sum Data

Panoos64

Well-known Member
Joined
Mar 1, 2014
Messages
882
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.

Terms StayAccomodation
A/P1262
A/P342
A/P1400
B/B855
B/B957
H/B1262
H/B2304
H/B342
H/B1970
H/B546
H/B1274
O/T1945
O/T2025

<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>
</tbody>



Schedule 2.

Terms StayAccomodation
A/P 3 RMS3004
B/B 2 RMS1812
H/B 6 RMS7698
O/T 2 RMS3970

<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>
</tbody>
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
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,216,558
Messages
6,131,400
Members
449,648
Latest member
kyouryo

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