Results 1 to 7 of 7

Help! Quick question on summing series

Threaded View

  1. #1
    Registered User
    Join Date
    10-06-2010
    Location
    TX
    MS-Off Ver
    Excel 2003
    Posts
    3

    Help! Quick question on summing series

    Basically, I need to write a VBA function which evaluates the function "1/i" for values from i = 1 to n. n can be any integer larger than one. It then adds all those terms to get the final answer. For example, if n = 4, the sum would be (1/1) + (1/2) + (1/3) + (1/4) = 2.083

    I can make the formula which evaluates 1/n, but not sure how to add the series starting at 1. I am referencing n from a value on the spreadsheet, and then pasting the final answer back onto the sheet.


    So far here is what I have:


    Option Explicit
    
    Function series(n As Integer) As Double
    
    
    
    series = (1 / n)
    
    
    End Function
    
    
    
    Sub sum()
    Dim n As Integer, x As Double
    
    
    With ThisWorkbook.Worksheets("Sheet1")
    n = .Cells(1, 1)
    End With
    
    
    x = series(n)
    
    
    With ThisWorkbook.Worksheets("Sheet1")
    .Cells(2, 1).Value = x
    End With
    
    
    End Sub
    Last edited by killadrilla; 10-06-2010 at 02:13 AM.

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