+ Reply to Thread
Results 1 to 8 of 8

object var or with block var not set

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

    object var or with block var not set

    can someone give me a little push here? I've tried all the breaks I can with this code and checked vars that have values in the immediate window and I can't seem to get why the worksheet object is not being set and transacted. It's been a while since I've written legacy VB like this, so I'm sure it's probably something very simple. Here is my code:

    Please Login or Register  to view this content.
    the code fails on the first line of the loop:
    Please Login or Register  to view this content.
    every var returns a val in the immediate window if I break it on the error line except the worksheet object. Can someone spot my misstep? thank you so much.

    Adam
    Last edited by vba_php; 08-06-2020 at 01:55 AM.

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

    Re: object var or with block var not set

    I have added a Case Else which will report unknown states. As well as a test around the For Each loop to make sure ws is a valid reference.

    It could be that the users are following the instructions provided, which is to enter a state in LOWERCASE.
    As you then go on and compare that information to UPPERCASE states, which of course will fail to match any.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: object var or with block var not set

    s1 is lower case whereas select case uses upper where it is case sensitive.
    Try change to
    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor
    Join Date
    12-14-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2007
    Posts
    439

    Re: object var or with block var not set

    Try add Option Compare Text at beginning of the module and add the red lines
    Please Login or Register  to view this content.

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

    Re: object var or with block var not set

    ha ha ha. thank you for spotting my nonsense Andy. =) I only need a part of your addition. this fixed it just fine:
    Please Login or Register  to view this content.
    I haven't written VB in a long time, but before that I wrote it for 20 years. Can't believe I overlooked such simplicity! Oh, and by the way, this is just being produced. no users are actually using it yet. which makes it even worse. I couldn't spot the mistake during my own testing phase! thanks again. have a good day.

  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 var or with block var not set

    and thanks to the others who also replied.

  7. #7
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,150

    Re: object var or with block var not set

    ?
    Please Login or Register  to view this content.

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

    Re: object var or with block var not set

    porucha,

    thank you for your contribution. I just saw it. I always know that my coding routines are not the most efficient possible. I don't give much thought into making them so. Your routine is obviously much better than mine. Appreciate it. If I ever do change it, I will consolidate it in that way.

+ 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] Object or With Block Error
    By 5150 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-19-2014, 11:20 AM
  2. macro block object
    By max_max in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-20-2013, 12:57 PM
  3. [SOLVED] Object Variable or with block not set
    By KeithMale in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-18-2013, 04:46 PM
  4. [SOLVED] Object Variable/With Block Not Set When Naming Ranges
    By sperry2565 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-09-2013, 12:59 PM
  5. [SOLVED] Object Variable Or With Block Not Set
    By AlexRoberts in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-28-2011, 06:27 AM
  6. Error #91 Object Variable or With Block Not Set
    By t0m46 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-01-2010, 12:07 PM
  7. object variable or with block not set
    By jhahes in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-11-2006, 04:45 AM
  8. Object variable or with block not set
    By Benny5788 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-11-2005, 02: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