+ Reply to Thread
Results 1 to 11 of 11

Compile error: Object required

  1. #1
    Registered User
    Join Date
    04-18-2007
    Posts
    2

    Compile error: Object required

    Hello!

    The following code produces a "Compile error:Object required". However, i don't see where an argument might be missing. I tried the same code without the 'Dim' and 'Set' (when are they required anyway? i have no clue...), then i get a "ByRef type mismatch" error.

    Can anyone help? I guess from the above questions it became clear that i am a beginner (for VBA, not otherwise). Please explain why the error happens and what's the correct way to fix it. Please do no completely rewrite the code, because in that case i probably will not learn the lesson that is hidden in this error.

    The error happens in this line:

    Please Login or Register  to view this content.
    However, if i remove the 'Set', the error moves a little forward to
    Please Login or Register  to view this content.
    Remove that 'Set' and the error moves to
    Please Login or Register  to view this content.
    Remove this 'Set' and the error change to the type mismatch on 'faAxis' in this line:
    Please Login or Register  to view this content.
    Questions:
    -What do these error messages mean?
    -Why do these errors appear?
    -Why do they appear on itemCount, Export and faAction, but not on faItem or faAxis?
    -Is there an easy solution to the problem?

    Thank you,

    Hinnerk

    Code:
    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    You have the first problems (use of set) because usually set is used with object, range, worksheet, workbook, etc.

    Problem
    Please Login or Register  to view this content.
    I think you have this problem because the Sub:
    Please Login or Register  to view this content.
    wants four string variables

    while you declared:
    Please Login or Register  to view this content.
    that it's not the same then write:
    Please Login or Register  to view this content.
    In your declaration VB assumes 'faItem' and 'faAxis' as variant (because you don't specify the cariable type) and only 'faAction' as String.

    Regards,
    Antonio

  3. #3
    Registered User
    Join Date
    04-18-2007
    Posts
    2
    Yes, that seems to be the problem. I removed all 'Set' and was more explicit about the types. It's very confusing that

    Please Login or Register  to view this content.
    does not declare two integers... since it is not, it should not even be allowed input.

    But hey, it's just Microsoft, so who cares?

    Thanks,

    Hinnerk

  4. #4
    Forum Expert
    Join Date
    11-23-2005
    Location
    Rome
    MS-Off Ver
    Ms Office 2016
    Posts
    1,628
    If you write:
    Please Login or Register  to view this content.
    Excel assumes 'A' as Variant and 'B' as Integer.

    You can also write so in one row:
    Please Login or Register  to view this content.
    Regards,
    Antonio

  5. #5
    Registered User
    Join Date
    05-10-2012
    Location
    houston, TX
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Compile error: Object required

    Hello,
    i saw you post and i am having a simular problem but iam not sure if it is the same fix can you help me out please.
    i am using the set for iLastRow(IE: getting the last row count in order to auto fill based off that value)


    My code keeps crashing on the Set iLastRow....etc...

    Please Login or Register  to view this content.
    Please help

  6. #6
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: Compile error: Object required

    remove the word Set. a number is not an object so does not need Set
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  7. #7
    Registered User
    Join Date
    05-10-2012
    Location
    houston, TX
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Compile error: Object required

    thanks for you response JosephP

  8. #8
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Compile error: Object required

    Also you are not making use of the With... End With

    Either use:

    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  9. #9
    Registered User
    Join Date
    05-10-2012
    Location
    houston, TX
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Compile error: Object required

    Abousetta,
    Thanks for your response but I am afraid that I do not follow you, are you saying that I should not use the “with.....End With”? You show two references one using it just like i have it written...
    i am having to use the with...end with due to I am getting the last row count on one sheet and using that value to auto fill down a column on a additional sheet.

    Please elaborate

  10. #10
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Compile error: Object required

    your 'with shtcomp' statement does nothing because you specify shtcomp again in the following line. you should either use the three line version abousetta posted first (though you should qualify the Rows property too) or the one line version he posted second, not a mix of the two.
    Remember what the dormouse said
    Feed your head

  11. #11
    Registered User
    Join Date
    05-10-2012
    Location
    houston, TX
    MS-Off Ver
    Excel 2010
    Posts
    10

    Re: Compile error: Object required

    AWE....
    thanks, for the clearfication. tying the revised code out now..

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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