Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 1 decade ago

Need help in Excel VBA creating custom functions.?

I'm trying to create a custom function to use in my excel spreadsheet. I've search the net and can't seem to find the right answers. Copied some examples from a book but that still didn't solve my problem. Please help.

I want to create a custom function to calculate sales tax. something like =CA(AmountPurchase)

I tried doing:

Function = CA(7.5, Cost)

CA = ((7.5) * Cost)

End Function

However, it keeps showing me an error.

Please help.

Update:

Hey thanks you guys!!!! I was reading a five inch book trying to figure out this problem.

Teach your self Excel Programming in 21 days my @ss. Took me about a week to understand the logic, vocab, keywords, etc...

Again, THANKS!!!!!!

3 Answers

Relevance
  • 1 decade ago
    Favorite Answer

    Your troubles are over.

    From the Excel menu bar, click Tools/Macro/Visual Basic Editor.

    In the VB Editor, clikc Insert/Module, and you'll get Module1.

    At the top you'll see Option Explicit. Skip a line (blank) and type the following:

    Public Function SalesTax(sglCost As Single) As Single

    SalesTax = sglCost * 0.075

    End Function

    Go back to the worksheets. Type "10" (without the quote marks) in a cell. In the cell next to it, type "=SalesTax(A1)" (without the quote marks). You should get 0.75.

    That's the basics of how to do it. Tweak it to suit your needs.

  • 5 years ago

    you need to use Excel applications by using using here syntax in VBA, right it incredibly is an occasion of the 'Sum' function, an identical utilized to the different geared up in Excel applications application.WorksheetFunction.Sum(Rang...

  • 1 decade ago

    you need to create the function in visual basic, I believe.

    http://office.microsoft.com/en-us/excel/HA01054846...

    In your case the function would go like this:

    Function GetTax(Tax,Cost)

    GetTax=(Tax/100)*Cost

    End Function

Still have questions? Get your answers by asking now.