Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Invoice aging - custom function

Am currently trying to write a custom function for aging of my
invoices which will be used in a macro in my Debtor statement report
- but it's not working as it looks to simple to be good. Can anybody
help thxs.

Function Age(StatementDate, InvDate)
If StatementDate - InvDate <= 30 Then Age = "Current"
If StatementDate - InvDate = 30 Then Age = "30 days"
If StatementDate - InvDate = 60 Then Age = "60 days"
If StatementDate - InvDate = 90 Then Age = "90 days"
If StatementDate = 150 Then Age = "150 days"
End Function

StatementDate & Invdate are in date format.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Invoice aging - custom function

Change
If StatementDate = 150 Then Age = "150 days"

to
If StatementDate - InvDate = 150 Then Age = "150 days"

StatementDate will always be 150, unless the date is in the first 5 months
of 1900....

HTH,
Bernie
MS Excel MVP


wrote in message
ups.com...
Am currently trying to write a custom function for aging of my
invoices which will be used in a macro in my Debtor statement report
- but it's not working as it looks to simple to be good. Can anybody
help thxs.

Function Age(StatementDate, InvDate)
If StatementDate - InvDate <= 30 Then Age = "Current"
If StatementDate - InvDate = 30 Then Age = "30 days"
If StatementDate - InvDate = 60 Then Age = "60 days"
If StatementDate - InvDate = 90 Then Age = "90 days"
If StatementDate = 150 Then Age = "150 days"
End Function

StatementDate & Invdate are in date format.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Invoice aging - custom function

Maybe something like:

Option Explicit
Function Age(StatementDate As Date, InvDate As Date) As String

Dim Diff As Long
Dim myStr As String

Diff = StatementDate - InvDate

Select Case Diff
Case Is <= 30: myStr = "Current"
Case Is < 60: myStr = "30 days"
Case Is < 90: myStr = "60 days"
Case Is < 150: myStr = "90 days"
Case Else
myStr = "150 days"
End Select

Age = myStr

End Function



wrote:

Am currently trying to write a custom function for aging of my
invoices which will be used in a macro in my Debtor statement report
- but it's not working as it looks to simple to be good. Can anybody
help thxs.

Function Age(StatementDate, InvDate)
If StatementDate - InvDate <= 30 Then Age = "Current"
If StatementDate - InvDate = 30 Then Age = "30 days"
If StatementDate - InvDate = 60 Then Age = "60 days"
If StatementDate - InvDate = 90 Then Age = "90 days"
If StatementDate = 150 Then Age = "150 days"
End Function

StatementDate & Invdate are in date format.


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Invoice aging - custom function

Hi,

I would say you have a problem in the ordering of your conditional statements.

Say, for example, StatementDate - InvDate = 65. The first condition that
matches is:
If StatementDate - InvDate = 30. As this condition is met then the
following conditional statements will not be tested (Presuming they are all
within the same If block using ElseIf). Try this instead:

If StatementDate - InvDate = 150 Then Age = "150 days"
ElseIf StatementDate - InvDate = 90 Then Age = "90 days"
ElseIf StatementDate - InvDate = 60 Then Age = "60 days"
ElseIf StatementDate - InvDate = 30 Then Age = "30 days"
Esle Age = "Current"
End If

Also, your first two conditions are true for 30 as they both contain the =
sign.

You could also use Select for situations like this, it usually leaves less
writing:

Select Case StatementDate - InvDate
Case = 150:Age = "150 days"
Case = 90:Age = "90 days"
Case = 60:Age = "60 days"
Case = 30:Age = "30 days"
Case Else:Age = "Current"
End Select

I hope this helps.

Sean.


" wrote:

Am currently trying to write a custom function for aging of my
invoices which will be used in a macro in my Debtor statement report
- but it's not working as it looks to simple to be good. Can anybody
help thxs.

Function Age(StatementDate, InvDate)
If StatementDate - InvDate <= 30 Then Age = "Current"
If StatementDate - InvDate = 30 Then Age = "30 days"
If StatementDate - InvDate = 60 Then Age = "60 days"
If StatementDate - InvDate = 90 Then Age = "90 days"
If StatementDate = 150 Then Age = "150 days"
End Function

StatementDate & Invdate are in date format.


Reply
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
invoice toolbar for invoice calcuation and assign number KarenY Excel Discussion (Misc queries) 15 March 16th 07 12:02 PM
Using SUMIF function with multiple criteria for Aging josnah Excel Worksheet Functions 2 June 4th 06 10:18 AM
missing invoice toolbar when save customised invoice M.G New Users to Excel 1 September 26th 05 07:18 AM
Invoice templet Excel97 to 2003 invoice toolbar missing MarolynInMarion Excel Discussion (Misc queries) 0 August 19th 05 07:15 PM
How do I change the invoice number assigned in Invoice template... akress Excel Discussion (Misc queries) 1 February 28th 05 06:36 PM


All times are GMT +1. The time now is 10:17 PM.

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"