+ Reply to Thread
Results 1 to 13 of 13

Excel vba function asking for object required error 424

  1. #1
    Registered User
    Join Date
    12-12-2013
    Location
    london, uk
    MS-Off Ver
    Excel 2003
    Posts
    9

    Excel vba function asking for object required error 424

    Hi,

    I have created the following function in excel

    Please Login or Register  to view this content.
    I then use the following to call it when the toggle button is clicked

    Please Login or Register  to view this content.
    However, I get the 424 error saying that an object is required.

    What is the reason behind this ?

    Thanks

    Bilal

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Excel vba function asking for object required error 424

    Hi Bilal

    Welcome to the Forum!!

    You don't tell us what line of Code is blowing out. Based on the posted Code I'd suggest these changes:

    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    12-12-2013
    Location
    london, uk
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Excel vba function asking for object required error 424

    Hi,

    This is the original sub I wrote for each toggle button and now I want to turn it into a function to make my code cleaner

    Please Login or Register  to view this content.
    The above works fine with no issues.

    Could you advise me on how best to turn this into a function ? The original thread heading was my attempt at writing a function.

    Bilal

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

    Re: Excel vba function asking for object required error 424

    What are ra_main_seasonals and tgbtnSeasonal?
    If posting code please use code tags, see here.

  5. #5
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,632

    Re: Excel vba function asking for object required error 424

    First: have you changed
    Please Login or Register  to view this content.
    into
    Please Login or Register  to view this content.
    As c2 is declared as Integer (it would be wiser to declare it as long) it cannot be Set. You can Set only object variables.

    so:
    Please Login or Register  to view this content.
    if it does not help, press Debug when code stops, chech which code line is highlited in yellow and let us know.

  6. #6
    Registered User
    Join Date
    12-12-2013
    Location
    london, uk
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Excel vba function asking for object required error 424

    Hi,

    rg_main_seasonals and tgbtnSeasonal are named ranges and toggle button respectively.

    I want to turn that sub routine into a function so that I can reuse it for the other toggle buttons on the page by just passing through the named range and toggle button name.

    Is that possible ?

    Bilal

  7. #7
    Registered User
    Join Date
    12-12-2013
    Location
    london, uk
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Excel vba function asking for object required error 424

    Quote Originally Posted by Kaper View Post
    First: have you changed
    Please Login or Register  to view this content.
    into
    Please Login or Register  to view this content.
    As c2 is declared as Integer (it would be wiser to declare it as long) it cannot be Set. You can Set only object variables.

    so:
    Please Login or Register  to view this content.
    if it does not help, press Debug when code stops, chech which code line is highlited in yellow and let us know.

    I have made this change. However, I want to turn my sub routine into a function so that I can then reuse it for the other toggle buttons by just passing through the named range and toggle button name.

    However, when I try to call it, it says object required.

    Any suggestions ?

    Bilal

  8. #8
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,632

    Re: Excel vba function asking for object required error 424

    OK. We know what error message you are getting.
    But ... Where the code execution stops?

    PS. is rg_main_seasonals the name of the range or range object
    I mean: (Ctrl+F3) ... rg_main_seasonals
    or
    Please Login or Register  to view this content.
    if it is the first case (just named range) then you shall call
    Please Login or Register  to view this content.

    Edit: I noticed after posting (I used parts of your previous messages copied into this answer):
    Isn't it just a problem with missspelling:
    ra_main_seasonals
    vs.
    rg_main_seasonals

    (the cure for such problems is using Option Explicit to force variable declarations)
    Last edited by Kaper; 12-14-2013 at 08:55 AM.

  9. #9
    Registered User
    Join Date
    12-12-2013
    Location
    london, uk
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Excel vba function asking for object required error 424

    Hi,

    I made the following change of adding range into the call function and proceeds. Now the code stops here

    Please Login or Register  to view this content.
    Why is that ? do I not need to write sht.range ?

    Bilal

  10. #10
    Registered User
    Join Date
    12-12-2013
    Location
    london, uk
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Excel vba function asking for object required error 424

    The error I now get is Run time 1004

    "Method, 'range' of object '_worksheet' failed"

    Why could that be ?

    Bilal

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

    Re: Excel vba function asking for object required error 424

    Can you post the exact code you have now, and an example of how you are calling it?

  12. #12
    Registered User
    Join Date
    12-12-2013
    Location
    london, uk
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Excel vba function asking for object required error 424

    Fixed,

    I was calling the range into the module which was playing up.

    It is
    Please Login or Register  to view this content.

    Thank you very much all !!!

  13. #13
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Excel vba function asking for object required error 424

    You might use code like this
    Please Login or Register  to view this content.
    Its not clear to me what the rng variable is used for. Perhaps changing the With line to
    Please Login or Register  to view this content.
    would be what you want. Then the range rg_main_tablets would have to be passed to the function as an argument.

    Also, its not clear what value you want returned by the function.

    (BTW, row visibility cannot be controlled by a UDF called from a worksheet formula, neither can the caption of a toggle button).
    Last edited by mikerickson; 12-14-2013 at 04:23 PM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

+ 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. [SOLVED] Run time error 424: Object Required in Outlook/Excel VBA
    By sirhacksalot in forum Excel General
    Replies: 9
    Last Post: 12-07-2013, 11:09 AM
  2. Excel VBA Error Code 424 Object Required
    By jeskit in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-14-2011, 08:27 AM
  3. Object Required Error in VB Excel Program that Passes Range to a function
    By navs8603 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-06-2011, 05:10 AM
  4. Object Required error on Application.Match function.
    By ctckark1 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-12-2011, 11:01 AM
  5. Excel 2007 Unable to .pastespecial, Error 'object required'
    By CMSS in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-09-2010, 10:34 AM

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