ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro to calculate percentage (https://www.excelbanter.com/excel-programming/297041-macro-calculate-percentage.html)

vikram

macro to calculate percentage
 
i have attached a small spreadsheet

in yellow column i need percentage (for example G5/G11) but the proble
is that number of rows keep changing like instead of G11 it can b
G100,G500

another problem is that i want persentage column in column J becos th
columns can go upto I

please suggest
i will be thankful to u al

Attachment filename: book12.xls
Download attachment: http://www.excelforum.com/attachment.php?postid=53213
--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

macro to calculate percentage
 
Hi Vikram,

Try this
Sub Percentages()
Dim iLastRow As Long
Dim i As Long

iLastRow = Cells(Rows.Count, "G").End(xlUp).Row
For i = 5 To iLastRow - 1
If Cells(i, "G").Value < "" Then
With Cells(i, "J")
.Formula = "=G" & i & "/G" & iLastRow
.NumberFormat = "0.0%"
End With
End If
Next i
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"vikram " wrote in message
...
i have attached a small spreadsheet

in yellow column i need percentage (for example G5/G11) but the problem
is that number of rows keep changing like instead of G11 it can be
G100,G500

another problem is that i want persentage column in column J becos the
columns can go upto I

please suggest
i will be thankful to u all

Attachment filename: book12.xls
Download attachment:

http://www.excelforum.com/attachment.php?postid=532130
---
Message posted from http://www.ExcelForum.com/




vikram

macro to calculate percentage
 
thank u so much for ur help

i forgoit to tell u something in that
the problem is that even column keeps changing
like u told me for G but sometimes it is E or F

what do u suggest
i appreciate ur help so muc

--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

macro to calculate percentage
 
to cater for it needs a rule What is the rule that determines whether it is
E, F or G?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"vikram " wrote in message
...
thank u so much for ur help

i forgoit to tell u something in that
the problem is that even column keeps changing
like u told me for G but sometimes it is E or F

what do u suggest
i appreciate ur help so much


---
Message posted from http://www.ExcelForum.com/




vikram

macro to calculate percentage
 
it is a pivot and it the columns in that pivot keeps changing.....so
want that whwtever is the last range cell....which is always a total o
which we calculate percentage

and percentage column should remain J


thank u so muc

--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

macro to calculate percentage
 
Maybe this will work it

Sub Percentages()
Dim iLastRow As Long
Dim iLastCol As Long
Dim i As Long

iLastCol = Cells(4, Columns.Count).End(xlToLeft).Column
iLastRow = Cells(Rows.Count, iLastCol).End(xlUp).Row
For i = 5 To iLastRow - 1
If Cells(i, iLastCol).Value < "" Then
With Cells(i, "J")
.FormulaR1C1 = "=RC" & iLastCol & "/R" & iLastRow & "C" &
iLastCol
.NumberFormat = "0.0%"
End With
End If
Next i
End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"vikram " wrote in message
...
it is a pivot and it the columns in that pivot keeps changing.....so i
want that whwtever is the last range cell....which is always a total on
which we calculate percentage

and percentage column should remain J


thank u so much


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 10:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com