LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Use a VBA function to return a factor

I'm developing a template program to allocate income amounts to 4 different
classes based upon prorate factors that can vary by category of income and
effective date of the prorate factors. The table of factors is on the same
sheet as the list (database) of income amounts to be allocated.

Here is a sample of prorate factors:
Category Date HSP CP
EpicInc 8/31/2001 0.49 0.51
InterestInc 8/31/2001 1
InterestInc 10/1/2002 0.6 0.4
RentInc 8/31/2001 1
RentInc 9/30/2002 0.56 0.50
RentInc 1/31/2004 1

Here is the Function proceedu

Function DepLookup(Cat As Range, TDate As Range)
' Looks up allocation based upon Category and date. IncTable is a named range
' on the worksheet containing the categories, effective dates and prorate
percentages.

Dim rng As Range
Dim workrange As Range, CatRows As Integer

Sheets("Database").Select
Set rng = Sheets("database").Range("IncTable")
rng.AutoFilter
rng.AutoFilter Field:=1, Criteria1:=Cat


'the following statement removes the first or header row
Set rng = rng.Offset(1, 0).Resize(rng.Rows.Count - 1)
Set rng = rng.SpecialCells(xlVisible)


If rng.Rows.Count = 0 Then
DepLookup = 0
End If
If rng.Rows.Count = 1 Then
DepLookup = rng.Range("C1").Value
End If
If rng.Rows.Count 1 Then
CatRows = rng.Rows.Count
Set workrange = rng.Range(Cells(1, 2), Cells(CatRows, 3))
DepLookup = Application.WorksheetFunction.Lookup(TDate, workrange)
End If

End Function

It works for the RentInc line item, but not the other categories. The
troubling thing is the effective date of a line of prorate factors. Prorate
factors are effective on and after the effective date and are superceded by a
line item with a later effective date. The data has dates back through
several years.

A sub proceedure with this same code works. I want a function procedure so
the results times the amount to be allocated will be entered in the cell with
the Function Proceedure.

Much of the code I borrowed from other entries/answers on this forum and I
appreciate the help a bunch. I've not found another that addresses this
problem specifically.

Any help will be appreciated.

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Time factor Debbie Excel Worksheet Functions 7 June 8th 09 10:22 PM
Any function to determine the smallest common factor from a list? Eric Excel Discussion (Misc queries) 4 December 10th 06 07:47 PM
Factor Analysis Mary Excel Worksheet Functions 1 July 26th 06 06:53 PM
IF FACTOR? Bernadette Excel Discussion (Misc queries) 2 June 8th 06 01:51 PM
Getting Zoom Factor HA Excel Programming 11 May 5th 06 11:49 AM


All times are GMT +1. The time now is 12:00 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"