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
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
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
Thanks Leith for your input!
/Peter
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
Thanks Dave for your code!
/Peter
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks