+ Reply to Thread
Results 1 to 5 of 5

Percentage Calculation using VBA

  1. #1
    Peter
    Guest

    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

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    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

  3. #3
    Dave Peterson
    Guest

    Re: 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

  4. #4
    Peter
    Guest

    Re: Percentage Calculation using VBA


    Thanks Leith for your input!

    /Peter

  5. #5
    Peter
    Guest

    Re: Percentage Calculation using VBA


    Thanks Dave for your code!

    /Peter

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1