How to create Excel function/formula?

This is the reason why the power of Excel when combined with VBA is almost limitless. When we can’t found any Excel function that suite our need, we can built it easily using Excel VBA.

If Excel macro or SUB procedure is easily created using Record Macro button, and usually build to simplify a complex process to became one simple push button or call, then an Excel function build to return a value from any kind of calculation and can be use and invoke as a formula.

For example, we can create a simple Excel function to get the last date of the month with date as parameter.

Public Function LASTDATEOFMONTH(ByVal TheDate As Variant) As Date
   Dim nLastDay As Integer
   nLastDay = DatePart("d", DateAdd("d", -1, DateAdd("m", 1, DateAdd("d", _
     -DatePart("d", TheDate) + 1, TheDate))))
   LASTDATEOFMONTH = DateSerial(Year(TheDate), Month(TheDate), nLastDay)
End Function

See the following result.

Last Date Of Month Excel Formula

The result of the formula shows us that the last date of this month is June 30, 2008.

Using Excel function, we can create any kind of specific formula that’s not available in Excel and need to be used for several time on our Excel project.

This entry was posted in Excel Formula and tagged . Bookmark the permalink.

933 Responses to How to create Excel function/formula?

  1. Robert says:

    Hi there,
    Just a question on VBA functions, say if I created a function for one project, I can’t use the same function on the other project. (unless I copy and paste the code to the module under that project. I’ve noticed that there is a PERSONAL.xls project always in VBA no matter what excel project I’m on. but I tried to copy the function in there it still doesn’t work.

    Could you please help?

    thank you very much!

    Robert

  2. admin says:

    hi robert, please make sure that you use public keyword in the module, like in the example above i use “public function”.

    if we state “public” in front of function or sub, that this method can be called from anywhere in the same project.

    hope this will help you.

  3. Duncan says:

    Hi, I wonder if you can help me please, I am having a problem with a user form in which I want to calculate a ‘Private Drawing’ perecentage deduction from a Full purchase amount to give a Taxable amount. The user would choose one of a number of perecentages from a list having entered the full price, then click a cmd button for a sub that should take price and deduct (the price times say .1 (10%)), instead it just zeroes the full price, I want the user to see this figure before clicking OK and sending all the other purchase details into the sheet. Sorry if this is long-winded. Thanks Duncan

  4. Sravan says:

    Hi,

    I want to get the row value(cud be groups of wrds) into new sheet.
    Similarly, i want to get this kind of information from different worksheets into one consolidate sheet.
    Here, i dunno the number of rows in particular worksheet. But i want all row information.

    Please help me in this…
    Please leave reply to sravandotcom@gmail.com or sravankumar.nallana@cognizant.com;
    Please call me at 9025638147.

    thanks

  5. Pingback: cheating wife website

  6. Pingback: cheap christian dior shoes

  7. Pingback: Breville BJE820XL Dual Disc Juicer

  8. Pingback: organic seo company

  9. Pingback: reverse mortgage loan

  10. Pingback: debt consolidation company

  11. Pingback: feuerlandkirsch.de/alles-uber-routenplaner

  12. Pingback: Anonymous

  13. Pingback: cul

  14. Pingback: ares free file downloads

  15. Pingback: ear popping

  16. Pingback: debt collection rate

  17. Pingback: collection agency rates

  18. Pingback: latest casino bonuses

  19. Pingback: Guided Christian Meditation

  20. Pingback: erotische masage

  21. Pingback: vimax

  22. Pingback: wedding photographer calgary

  23. Pingback: how to enlarge

  24. Pingback: hier

  25. Pingback: Wedding Photography

  26. Pingback: ???????????

  27. Pingback: have an affair

  28. Pingback: Cheap Fitflop Toning Shoe

  29. Pingback: cushion cut egagement ring

  30. Pingback: wie kann ich schnell abnehmen

  31. Pingback: madison street beauty

  32. Pingback: Sexlijnen

  33. Pingback: Gaming Mouse Reviews

  34. Pingback: ?????????? ??????????

  35. Pingback: Apps For Kids

  36. Pingback: more

  37. Pingback: devis assurance auto

  38. Pingback: hobby lobby coupon

  39. Pingback: prets personnels

  40. Pingback: credit monitoring

  41. Pingback: tricksterzz

  42. Pingback: kamagra

  43. Pingback: ??? ???????

  44. Pingback: job hunter

  45. Pingback: hobby lobby coupon

  46. Pingback: chota bheem games

  47. Pingback: Justin Bieber Online Games

  48. Pingback: Amazon promotional code

  49. Pingback: http://jawadsatti.com/

  50. Pingback: chhota bheem games

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>