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

#### Costa_Mukhar

##### New Member
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

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
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``````

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.

Hi....I fixed it by multiplying the formula by 2, and it works fine now.

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

Replies
3
Views
69
Replies
0
Views
71
Replies
7
Views
124
Replies
8
Views
113
Replies
19
Views
805

1,196,414
Messages
6,015,126
Members
441,873
Latest member
saustark

### 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.

### Which adblocker are you using?

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

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