VBA - Percentage calculation for a variable number of cells in a column

Costa_Mukhar

New Member
Joined
Jun 6, 2015
Messages
20
Hi,

I have a column that have different values with the column total at the end. I need a code to calculate the percentage/weight of each cell out of the column total, taking into consideration that cell numbers in the column are variable, everyday I may have different number of values/cells.

The column starts at cell L5 & I need to show the percentage of each cell starting from cell M5

Can somebody help me with the code, many thanks.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Try,,,

Code:
Sub AddPercentages()
LR = Range("L" & Rows.Count).End(xlUp).Row  ' determined the last non-blank row in your Column L
Columns("M:M").NumberFormat = "0.00%"
With Range("M5:M" & LR)
    .Formula = "=L5/Sum(L:L)"
End With
End Sub
 
Upvote 0
thanks for your reply, but
Code:
.Formula = "=L5/Sum(L:L)"
is including the sum of the column as well.

there are other columns in the table to decide the range of the cells to include in the sum, lets say column B, which has the same number of cells column L has.
 
Upvote 0
Hi....I fixed it by multiplying the formula by 2, and it works fine now.

.Formula = "=L5/Sum(L:L)*2"

Many thanks for your help
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,937
Members
449,094
Latest member
teemeren

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