+ Reply to Thread
Results 1 to 19 of 19

Object variable or with block variable

  1. #1
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,733

    Object variable or with block variable

    Hi guys,

    I get this message at the end of my search "OBJECT VARIABLE OR WITH BLOCK VARIABLE NOT SET". Some of my search I don't get the message but some of them did get the message.

    Please tell me why. Thanks.




    Please Login or Register  to view this content.

  2. #2
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Object variable or with block variable

    first of all, are you sure this line is right?
    Please Login or Register  to view this content.
    usually, anything that is associated with a visible property returns a bool type, not a long.

    secondly, what line does that error occur on?

    more than likely what is happening is that you're running into data in a cell that the code doesn't like. and there are probably an endless amount of possibilities for that scenario. I did not look at your file.

  3. #3
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,120

    Re: Object variable or with block variable

    I can see nothing wrong with that code & it should work.
    Although if it unhides a sheet & you click Cancel it won't rehide the sheet.

    What line does it fail on & what were you doing?

  4. #4
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,733

    Re: Object variable or with block variable

    Hi
    I attached the file. Please check.

    If you click the "search" button and search for Test and at the end you will the message "OBJECT VARIABLE OR WITH BLOCK VARIABLE NOT SET".

    I also noticed that if you add another Test to search, then the message disappear. If I have one or two of the Test to search that is when the message appeared.

    Thanks.
    Attached Files Attached Files

  5. #5
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Object variable or with block variable

    @vba_php, worksheet visibility has 3 states so a long is valid. Visible, Hidden and VeryHidden.
    Cheers
    Andy
    www.andypope.info

  6. #6
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Object variable or with block variable

    i was aware of all 3 properties andy. i will look them up to verify that i know what i'm talking about. thank.s
    Last edited by AliGW; 08-28-2020 at 03:10 AM. Reason: Please don't quote unnecessarily!

  7. #7
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Object variable or with block variable

    The FindNext returns nothing so you need to check for that. This does appear to be at odds with the help description which describes FindNext looping around and then returning to first found instance.

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,733

    Re: Object variable or with block variable

    Hi

    What Do I need to do? Sorry, I am not an expert with the VBA.

    Do I need to replace any in the code?

    Thanks

  9. #9
    Banned User!
    Join Date
    02-06-2020
    Location
    Iowa City, IA, USA
    MS-Off Ver
    2016 - 365 / 2007
    Posts
    2,014

    Re: Object variable or with block variable

    Quote Originally Posted by RJ1969 View Post
    Hi

    What Do I need to do? Sorry, I am not an expert with the VBA.

    Do I need to replace any in the code?

    Thanks
    I think andy has told you what to do. are you not following?

  10. #10
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,733

    Re: Object variable or with block variable

    Sorry,
    But I saw the code he provided but I don't know where to place the code with the rest.

    Please Login or Register  to view this content.
    Like, I said I am not good in VBA.

  11. #11
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,733

    Re: Object variable or with block variable

    I don't if I am adding the code into the rest of the code which I don't know where place. Or I am deleting some from the original code and replace it.

    Thanks.

  12. #12
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,120

    Re: Object variable or with block variable

    You just need to add the middle of those 3 lines, into your code between the other two lines

  13. #13
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,733

    Re: Object variable or with block variable

    what 3 lines?

    is this correct:

    Please Login or Register  to view this content.

  14. #14
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,120

    Re: Object variable or with block variable

    No just add this line
    Please Login or Register  to view this content.
    between these two, in your original code
    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,733

    Re: Object variable or with block variable

    it still does the same :o(

    see attachment.
    Last edited by RJ1969; 08-28-2020 at 02:53 PM.

  16. #16
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,733

    Re: Object variable or with block variable

    Hi All
    Never mind. I got it. I added the wrong code... sorry.

    Thank you All.

  17. #17
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,120

    Re: Object variable or with block variable

    Glad to help & thanks for the feedback.

  18. #18
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,629

    Re: Object variable or with block variable

    Please Login or Register  to view this content.
    Ben Van Johnson

  19. #19
    Forum Contributor
    Join Date
    10-05-2014
    Location
    CALIFORNIA
    MS-Off Ver
    2010
    Posts
    1,733

    Re: Object variable or with block variable

    Thank you ProtonLeah

+ 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. Replies: 12
    Last Post: 12-28-2019, 12:29 PM
  2. [SOLVED] Run-time error '91': Object variable or With block variable not set when closing userform
    By bishoposiris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2016, 08:59 AM
  3. Replies: 2
    Last Post: 08-22-2014, 03:55 AM
  4. Replies: 1
    Last Post: 07-24-2013, 02:45 PM
  5. Replies: 4
    Last Post: 07-12-2013, 12:14 PM
  6. Replies: 0
    Last Post: 04-16-2013, 07:15 AM
  7. Replies: 6
    Last Post: 12-21-2012, 08:03 AM

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