Hi all, I would like to write a VBA code so that, to sort by alphabetical order, by “CATEGORY” heading, beginning from row “A5” but excluding the last row which is the “Totals” row. I present below the original data and the expected result.
Thanking you in advance
ORIGINAL DATA
<tbody>[TR]
[TD="width: 32, align: center"][/TD]
[TD="width: 195"]
A
[TD="width: 92"]
B
[TD="width: 92"]
C
[TD="width: 92"]
D
[/TD]
[TD="width: 92"]
E
[/TD]
[TD="width: 92"]
F
[/TD]
[TD="width: 92"]
G
[/TD]
[TD="width: 92"]
H
[/TD]
[/TR]
[TR]
[TD="width: 32"]
4
[/TD]
[TD="width: 195"]
CATEGORY
[/TD]
[TD="width: 92"]
JAN COST
[/TD]
[TD="width: 92"]
FEB COST
[/TD]
[TD="width: 92"]
MAR COST
[/TD]
[TD="width: 92"]
APR COST
[/TD]
[TD="width: 92"]
MAY COST
[/TD]
[TD="width: 92"]
JUN COST
[/TD]
[TD="width: 92"]
JUL COST
[/TD]
[/TR]
[TR]
[TD="width: 32"]
5
[TD="width: 195"]
SOFT DRINKS
[TD="width: 92"]
1,501.00
[TD="width: 92"]
1,756.00
[TD="width: 92"]
1,874.00
[TD="width: 92"]
2,105.00
[TD="width: 92"]
2,325.00
[TD="width: 92"]
3,128.00
[TD="width: 92"]
4,258.00
[/TR]
[TR]
[TD="width: 32"]
6
[TD="width: 195"]
SPIRITS & ALCOHOLICS
[TD="width: 92"]
855.00
[TD="width: 92"]
910.00
[TD="width: 92"]
1,241.00
[TD="width: 92"]
1,105.00
[TD="width: 92"]
1,855.00
[TD="width: 92"]
1,458.00
[TD="width: 92"]
1,785.00
[/TR]
[TR]
[TD="width: 32"]
7
[/TD]
[TD="width: 195"]
CEREALS & BAKERIES
[TD="width: 92"]
457.00
[TD="width: 92"]
589.00
[TD="width: 92"]
659.00
[TD="width: 92"]
478.00
[TD="width: 92"]
558.00
[TD="width: 92"]
378.00
[TD="width: 92"]
459.00
[/TR]
[TR]
[TD="width: 32"]
8
[TD="width: 195"]
HOT BEVERAGES
[TD="width: 92"]
455.00
[TD="width: 92"]
357.00
[TD="width: 92"]
378.00
[TD="width: 92"]
310.00
[TD="width: 92"]
278.00
[TD="width: 92"]
290.00
[TD="width: 92"]
283.00
[/TR]
[TR]
[TD="width: 32"]
9
[TD="width: 195"]
APERITIFS
[TD="width: 92"]
125.00
[TD="width: 92"]
220.00
[TD="width: 92"]
142.00
[TD="width: 92"]
238.00
[TD="width: 92"]
345.00
[TD="width: 92"]
248.00
[TD="width: 92"]
275.00
[/TR]
[TR]
[TD="width: 32"]
10
[/TD]
[TD="width: 195, align: center"][/TD]
[TD="width: 92"]
3,393.00
[TD="width: 92"]
3,832.00
[TD="width: 92"]
4,294.00
[TD="width: 92"]
4,236.00
[TD="width: 92"]
5,361.00
[TD="width: 92"]
5,502.00
[TD="width: 92"]
7,060.00
[/TR]
</tbody>[/TABLE]
EXPECTED RESULT
[TABLE="class: MsoNormalTable, width: 514"]
<tbody>[TR]
[TD="width: 32, align: center"][/TD]
[TD="width: 184"]
A
[TD="width: 92"]
B
[TD="width: 92"]
C
[TD="width: 92"]
D
[/TD]
[TD="width: 92"]
E
[/TD]
[TD="width: 92"]
F
[/TD]
[TD="width: 92"]
G
[/TD]
[TD="width: 92"]
H
[/TD]
[/TR]
[TR]
[TD="width: 32"]
4
[/TD]
[TD="width: 184"]
CATEGORY
[/TD]
[TD="width: 92"]
JAN COST
[/TD]
[TD="width: 92"]
FEB COST
[/TD]
[TD="width: 92"]
MAR COST
[/TD]
[TD="width: 92"]
APR COST
[/TD]
[TD="width: 92"]
MAY COST
[/TD]
[TD="width: 92"]
JUN COST
[/TD]
[TD="width: 92"]
JUL COST
[/TD]
[/TR]
[TR]
[TD="width: 32"]
5
[TD="width: 184"]
APERITIFS
[TD="width: 92"]
125.00
[TD="width: 92"]
220.00
[TD="width: 92"]
142.00
[TD="width: 92"]
238.00
[TD="width: 92"]
345.00
[TD="width: 92"]
248.00
[TD="width: 92"]
275.00
[/TR]
[TR]
[TD="width: 32"]
6
[TD="width: 184"]
HOT BEVERAGES
[TD="width: 92"]
455.00
[TD="width: 92"]
357.00
[TD="width: 92"]
378.00
[TD="width: 92"]
310.00
[TD="width: 92"]
278.00
[TD="width: 92"]
290.00
[TD="width: 92"]
283.00
[/TR]
[TR]
[TD="width: 32"]
7
[/TD]
[TD="width: 184"]
CEREALS & BAKERIES
[TD="width: 92"]
457.00
[TD="width: 92"]
589.00
[TD="width: 92"]
659.00
[TD="width: 92"]
478.00
[TD="width: 92"]
558.00
[TD="width: 92"]
378.00
[TD="width: 92"]
459.00
[/TR]
[TR]
[TD="width: 32"]
8
[TD="width: 184"]
SOFT DRINKS
[TD="width: 92"]
1,501.00
[TD="width: 92"]
1,756.00
[TD="width: 92"]
1,874.00
[TD="width: 92"]
2,105.00
[TD="width: 92"]
2,325.00
[TD="width: 92"]
3,128.00
[TD="width: 92"]
4,258.00
[/TR]
[TR]
[TD="width: 32"]
9
[TD="width: 184"]
SPIRITS & ALCOHOLICS
[TD="width: 92"]
855.00
[TD="width: 92"]
910.00
[TD="width: 92"]
1,241.00
[TD="width: 92"]
1,105.00
[TD="width: 92"]
1,855.00
[TD="width: 92"]
1,458.00
[TD="width: 92"]
1,785.00
[/TR]
[TR]
[TD="width: 32"]
10
[/TD]
[TD="width: 184, align: center"][/TD]
[TD="width: 92"]
3,393.00
[TD="width: 92"]
3,832.00
[TD="width: 92"]
4,294.00
[TD="width: 92"]
4,236.00
[TD="width: 92"]
5,361.00
[TD="width: 92"]
5,502.00
[TD="width: 92"]
7,060.00
[/TR]
</tbody>[/TABLE]
Last edited: