+ Reply to Thread
Results 1 to 7 of 7

Vba function

  1. #1
    Registered User
    Join Date
    08-29-2019
    Location
    Lisbon, Portugal
    MS-Off Ver
    2020
    Posts
    8

    Question Vba function

    Hello,
    I need a VBA funcion that does the following:

    Please Login or Register  to view this content.
    Thanks for the help.
    Last edited by Pepe Le Mokko; 08-30-2019 at 11:06 AM.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,811

    Re: Vba function

    This forum can be strict about rules (like putting code in code tags and giving descriptive thread titles). You will want to edit your post to include those code tags (see the forums FAQ link for instructions if you are unfamiliar) so that your topic does not get locked.

    You might also provide a better description of what the code is doing/should be doing so we can better understand it. I see a lot of undefined/uninitialized variables in your code, which makes it difficult to understand exactly what you are doing. Some of what you have suggests to me that we will need to know what you know about arrays (and maybe other data types), so helping us understand what you know will help us help you.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,446

    Re: Vba function

    Administrative Note:

    Fallowing on MrShorty's comment:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    As you are rather new here, I will do it for you this time. Have you read and understood our forum rules?

  4. #4
    Registered User
    Join Date
    08-29-2019
    Location
    Lisbon, Portugal
    MS-Off Ver
    2020
    Posts
    8

    Re: Vba function

    Sorry, I didnt't know that I had to use tags on code and I didn't understant what MrShorty meant by code tags

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,811

    Re: Vba function

    I'm still not sure what the code is trying to do. What I see the code doing is repeatedly evaluating the same expression at different values for ni.

    IMO, this looks very similar to a previous thread (https://www.excelforum.com/excel-pro...in-angles.html ). It appears that you have rejected the lookup solution proposed in this thread without comment, and are pursuing what you have posted here.

    Comparing the two threads, the overall problem looks to me like a root finding problem (https://en.wikipedia.org/wiki/Root-finding_algorithm ). You appear to be wanting to use an inefficient "brute force" algorithm for this. Are you required to use a brute force algorithm, or could you use a more efficient algorithm? Are you required to program your own root finding algorithm, or could you use something pre-programmed?

    It appears that the expressions for Q are a little different between the two threads, but that should not impact the programmatic approach to the problem. Depending on how you answer the previous questions, I would approach the problem:

    A) Using Excel's built in Solver/Goal Seek tools which are based on Newton's method. I generally prefer Solver over Goal Seek. I will add a reply to the other thread detailing how I would setup Solver.
    B) Using spreadsheet formulas, implement my chosen root finding algorithm. I have a thread here that talks about implementing Newton's method in a spreadsheet: https://www.excelforum.com/tips-and-...ind-roots.html
    C) Write a VBA UDF (like what you are trying to do here) that will use my chosen root finding algorithm to find the root. The last post in the other thread includes an example of a VBA UDF that implements Newton's method for a polynomial.

    One key to implementing root finding algorithms in VBA (or similar programming language) is understanding loop structures. https://www.excelfunctions.net/vba-loops.html

  6. #6
    Registered User
    Join Date
    08-29-2019
    Location
    Lisbon, Portugal
    MS-Off Ver
    2020
    Posts
    8

    Thumbs up Re: Vba function

    Thank you for your help

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,926

    Re: Vba function

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however the thread title does not really convey what your request is about.

    Please take a moment to amend your thread title. Make sure that the title properly explains your request. Your title should be explicit and not be generic (this includes function names used without an indication of what you are trying to achieve).

    Please see Forum Rule #1 about proper thread titles and adjust accordingly. To edit the thread title, open the original post to edit and then click on Go Advanced (bottom right) to access the area where you can edit your title.

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. COUNTUNIQUE Function in Google Sheets; Excel lacks a direct counterpart to this function?
    By PivotTablePSHomage in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-18-2018, 05:27 AM
  2. Calling function inside function. (aka nested function)
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-02-2015, 05:58 AM
  3. Replies: 1
    Last Post: 06-10-2015, 12:56 PM
  4. Replies: 13
    Last Post: 04-08-2014, 05:46 AM
  5. Replies: 1
    Last Post: 03-21-2012, 11:22 AM
  6. Replies: 2
    Last Post: 03-20-2009, 01:29 PM
  7. [SOLVED] Excel - User Defined Function Error: This function takes no argume
    By BruceInCalgary in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2006, 04:05 PM

Tags for this Thread

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