+ Reply to Thread
Results 1 to 2 of 2

VBA Payback Function Problems

Hybrid View

  1. #1
    Registered User
    Join Date
    04-24-2014
    Location
    Boston, MA
    MS-Off Ver
    Excel 2007
    Posts
    13

    VBA Payback Function Problems

    Hi,

    I have attempted to write a basic vba code for calculating payback (the time it takes to get back your original investment using a stream of cash flows). Using some referenced code and writing some myself I have been unable to get it to output correctly. I have minimal experience in VBA so any help would be appreciated!


    Public Function mypayback(cashflow As Range)

    Dim csum As Single
    Dim time As Integer
    Dim total As Single
    Dim rangesum As Single

    total = 0

    For Each cell In cashflow
    total = total + cell.Value
    Next cell

    rangesum = total

    If cashflow(1) >= 0 Or rangesum < 0 Then
    mypayback = "No Value"
    Exit Function

    Else
    csum = 0
    For time = 1 To cashflow.Cells.Count
    csum = csum + cashflow(time)
    If csum > 0 Then
    Exit For
    End If
    Next time

    csum = csum - cashflow(time)

    mypayback = Period - 2 - csum / cashflow(time)

    End If



    End Function


    I think everything above the bold is correct but I am having difficulty understanding and following the bold part. I feel as though there must be an easier way to write it.

    Thanks!

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: VBA Payback Function Problems

    What's the question?

    Where is the variable Period defined?
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Stuck: Need help with original vba code for irr & payback function
    By bkuchen in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 04-25-2014, 02:04 PM
  2. Function that calculates payback period won't work
    By smoothopia in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-13-2014, 03:19 PM
  3. [SOLVED] Payback function/formula with a growth rate
    By jetablack4 in forum Excel General
    Replies: 19
    Last Post: 10-15-2012, 10:31 AM
  4. Payback Calculation
    By andrew8008 in forum Excel General
    Replies: 3
    Last Post: 06-18-2007, 01:20 AM
  5. How to create data tables and is there a payback period function
    By Austen T in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 07-18-2006, 12:10 PM

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