Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate a percentage

Status
Not open for further replies.

paulmtl

Programmer
Feb 25, 2005
27
CA
Hi all,

How to create the formula to calculate the percentage out of the total in general format can be used all along ? from myExcel.xls

account amount classcode percentage

11111 100 AAAAA 0.16
11111 200 AAAAA 0.34
11111 300 AAAAA 0.50
---------------
subtotal 600

11111 100 BBBBB 0.16
11111 200 BBBBB 0.34
11111 300 BBBBB 0.50
---------------
subtotal 600


22222 200 CCCCC 0.25
22222 200 CCCCC 0.25
22222 400 CCCCC 0.50
--------------
subtotal 800

22222 200 DDDDD 0.25
22222 200 DDDDD 0.25
22222 400 DDDDD 0.50
--------------
subtotal 800

I got the columns account , amount,classcode but need to calculate the percentage but be carefull , each time the account changes the formula of percentage should changed accordingly.

Please help me with the codes in VB because I am newbie to
VB to run as a macro or sub percent() for 10000 accounts in which it is not easy to do it with a single
formula.

Thanks in advance,



 
Hi all,

I started my coding to calculate :

account amount classcode percentage

11111 100 AAAAA 0.16
11111 200 AAAAA 0.34
11111 300 AAAAA 0.50
---------------
subtotal 600

11111 100 BBBBB 0.16
11111 200 BBBBB 0.34
11111 300 BBBBB 0.50
---------------
subtotal 600


here is the codes:

begins in row 17 and column 6 (account) & col 8 ( Amount )

For r = 17 To 19
c = 8
lcAmt = ActiveSheet.Cells(r, c).Value

For x = 17 To 20

lcAcct = ActiveSheet.Cells(x, 6).Value

If lcAcct = " " Then

lcSubtotal = ActiveSheet.Cells(x, c).Value

End If

Next

lcPercent = lcAmt / lcSubtotal

Range("T2").Value = lcPercent

Next

it only works for the first subtotal of 600, how to do the next loop in the subtotal of 800 , I need help.

Thanks again whoever can assist.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top