+ Reply to Thread
Results 1 to 11 of 11

MROUND Function Not Available in VBA

  1. #1
    Registered User
    Join Date
    02-05-2013
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    7

    MROUND Function Not Available in VBA

    Hello,

    I cannot get the MROUND(#,#) function to work in VBA. I'm working on a simple userform, and I need the scroll bar value to display in .25 increments. I have enabled the atpvbaen.xls add in for VBA, and the tool pack add in is also enabled in excel. I'm just not sure why the function is not available. When I try to call it with [atpvbaen.xls].MRound(#,#), I still get an error.

    Please let me know if you have any suggestions.

    Thank you.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: MROUND Function Not Available in VBA

    Are you using Application.WorksheetFunction.MRound?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    02-05-2013
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: MROUND Function Not Available in VBA

    Thanks for the quick response, I just tried that. I'm getting a run-time error '424': object required. Here is a sample of the equation that I used in the change event sub for the scroll bar I'm trying to use.

    Label1.Caption = Appication.WorksheetFunction.MRound(ScrollBar.Value, 0.25)

    Thanks for your help.

  4. #4
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: MROUND Function Not Available in VBA

    Please Login or Register  to view this content.
    You've got a typo - "Application", not "Appication".

  5. #5
    Registered User
    Join Date
    02-05-2013
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: MROUND Function Not Available in VBA

    Thanks Andrew-R for the response, I fixed the typo, but I still get the same error. Application.WorksheetFunction.MRound(ScrollBar.Value, 0.25)

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Do you have a ScrollBar called 'ScrollBar'?

  7. #7
    Registered User
    Join Date
    02-05-2013
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: MROUND Function Not Available in VBA

    Yes, I do. Thanks for the reply.

  8. #8
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: MROUND Function Not Available in VBA

    Perhaps we could take the MROUND out of the equation, then:

    Please Login or Register  to view this content.
    Does that resolve the error?

  9. #9
    Registered User
    Join Date
    02-05-2013
    Location
    Washington, DC
    MS-Off Ver
    Excel 2010
    Posts
    7

    Re: MROUND Function Not Available in VBA

    Yes, that works thank you! I'm still curious as to why the Mround function doesn't work, but that can wait for another day

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: MROUND Function Not Available in VBA

    In earlier versions I believe MROUND was part of the Analysis ToolPak.

    To use it in VBA you had to set a reference to ATPVBAEN.xls.

    Then it was available as just MRound.

    In later versions Analysis ToolPak is integrated so you don't need the Analysis Toolpak and can use MROUND like any other worksheet function.

    In VBA to access worksheet functions you use Application.WorksheetFunction.NameOfFunction or Application.NameOfFunction.

    So, since MROUND is just another worksheet function you access it like that.

    Or something like that anyway.

  11. #11
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: MROUND Function Not Available in VBA

    This seems to work

    temp = Excel.WorksheetFunction.MRound(12.345, 0.25)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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