ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Percentage Calculation using VBA (https://www.excelbanter.com/excel-programming/344865-percentage-calculation-using-vba.html)

Peter

Percentage Calculation using VBA
 
I want to calculate a percentage change between two cells and it would be
great if I could use the Range(Cells(4,4), Cells(5,4)) format. What is an
easy and clever solution to this problem using VBA code?

Thanks in advance!

/Peter

Leith Ross[_233_]

Percentage Calculation using VBA
 

Hello Peter,

The percentage difference is easy to calculate given 2 cells. Simply
divide the smaller value by the larger. However you posted you want the
percent change. That would require more than 2 cells. Are you looking to
examine a 2 groups of data so you have a Delta X column and Delta Y
column?

Thanks,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=482692


Dave Peterson

Percentage Calculation using VBA
 
Something like:

Option Explicit
Sub testme()

Dim myResult As Variant

myResult = "Error!"
With ActiveSheet
If IsNumeric(.Cells(4, 4).Value) Then
If IsNumeric(.Cells(5, 4).Value) Then
If .Cells(5, 4).Value < 0 Then
myResult = .Cells(4, 4).Value / .Cells(5, 4).Value / 100
End If
End If
End If
End With

MsgBox myResult
If IsNumeric(myResult) Then
MsgBox Format(myResult, "0.00%")
End If
End Sub



Peter wrote:

I want to calculate a percentage change between two cells and it would be
great if I could use the Range(Cells(4,4), Cells(5,4)) format. What is an
easy and clever solution to this problem using VBA code?

Thanks in advance!

/Peter


--

Dave Peterson

Peter

Percentage Calculation using VBA
 

Thanks Leith for your input!

/Peter

Peter

Percentage Calculation using VBA
 

Thanks Dave for your code!

/Peter


All times are GMT +1. The time now is 09:03 AM.

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