Results 1 to 6 of 6

Checking VBA code

Threaded View

  1. #1
    Registered User
    Join Date
    09-17-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    17

    Checking VBA code

    I apply the below function to the range that has the same dimension as x or defaultdata. However the function does not seem to work properly and returns #Value mistake. The function is run in Microsoft Office 2010.

    Cant figure out why the mistake occurs. Any assistance is much appreciated

    Function TRANS(defaultdata As Range, x As Range, numranges As Integer)
    
    Dim bound, numdefaults, obs, defrate, N, j, defsum, obssum, i
    ReDim bound(1 To numranges), numdefaults(1 To numranges)
    ReDim obs(1 To numranges), defrate(1 To numranges)
    
    N = x.Rows.Count
    
    defsum = 0
    obssum = 0
    
    'Determining number of defaults, observations and default rates for ranges
    For j = 1 To numranges
        
        bound(j) = Application.WorksheetFunction.Percentile(x, j / numranges)
        
        numdefaults(j) = Application.WorksheetFunction.SumIf(x, "<=" & bound(j), defaultdata) - defsum
        defsum = defsum + numdefaults(j)
    
        obs(j) = Application.WorksheetFunction.CountIf(x, "<=" & bound(j)) - obssum
        obssum = obssum + obs(j)
        
        defrate(j) = numdefaults(j) / obs(j)
    Next j
    
    'Assigning range default rates in logistic transformation
    Dim transform
    ReDim transform(1 To N, 1 To 1)
    
    For i = 1 To N
        j = 1
        While x(i) - bound(j) > 0
            j = j + 1
        Wend
        transform(i, 1) = Application.WorksheetFunction.Max(defrate(j), 0.0000001)
        transform(i, 1) = Log(transform(i, 1) / (1 - transform(i, 1)))
    Next i
    
    TRANS = numdefaults
    
    End Function
    The Excel file
    Attached Files Attached Files
    Last edited by Novosedoff; 02-17-2015 at 03:15 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Help with VBA code checking for Duplicates
    By anfdrew in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-02-2013, 11:44 PM
  2. Checking references automatically through code?
    By c.vaibhav in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-05-2009, 05:54 AM
  3. Error Checking Code
    By kylegwell in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-14-2007, 12:41 PM
  4. Color Code Date Checking
    By drvortex in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-01-2006, 03:35 AM
  5. checking VBA code
    By nkamp in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-27-2005, 02:38 AM

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