+ Reply to Thread
Results 1 to 6 of 6

Trouble-shooting a 'run-time error 91' with the definition of a range

  1. #1
    Registered User
    Join Date
    04-03-2014
    Location
    Woodbury, GA
    MS-Off Ver
    Excel 2010 and Excel 2013
    Posts
    37

    Question Trouble-shooting a 'run-time error 91' with the definition of a range

    I'm trying to gain a better feels for using ranges rather than trying to loop through cells and assign something dynamically that way; it seems more powerful, to me, to have a good understanding of how to define ranges and alter them dynamically. To this end I wrote the very small code below. This code gives me a "runtime error 91: object variable or with block variable not set."

    I know it's simple for many, but if someone could give me an explanation as to why this error occurs, I would be very appreciative.

    Here's the code...
    Please Login or Register  to view this content.
    Last edited by EverGreen1231; 01-07-2016 at 02:06 PM.

  2. #2
    Valued Forum Contributor Gatti's Avatar
    Join Date
    06-08-2015
    Location
    Brasil, São Paulo, Ribeirão Preto
    MS-Off Ver
    365
    Posts
    346

    Re: I would like help with this simple excersise.

    Substitute "Value" per "FormulaR1C1"

    This way:

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-03-2014
    Location
    Woodbury, GA
    MS-Off Ver
    Excel 2010 and Excel 2013
    Posts
    37

    Re: I would like help with this simple excersise.

    It still gives the same error.

  4. #4
    Registered User
    Join Date
    04-03-2014
    Location
    Woodbury, GA
    MS-Off Ver
    Excel 2010 and Excel 2013
    Posts
    37

    Re: I would like help with this simple excersise.

    Quote Originally Posted by Gatti View Post
    Substitute "Value" per "FormulaR1C1"

    This way:

    Please Login or Register  to view this content.
    It still gives the same error.

  5. #5
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,810

    Re: I would like help with this simple excersise.

    from the error statement:
    "runtime error 91: object variable or with block variable not set." [emphasis mine]
    Your assignment statement neglects to include the "Set" keyword. Where the "Let" keyword is optional (and frequently left out) of Let statements, the Set keyword is not optional in Set statements https://msdn.microsoft.com/EN-US/lib.../gg251642.aspx

    I think it should work just fine if you include the Set keyword when you assign the range to rng
    Set rng=thisworkbook.....
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  6. #6
    Registered User
    Join Date
    04-03-2014
    Location
    Woodbury, GA
    MS-Off Ver
    Excel 2010 and Excel 2013
    Posts
    37

    Re: I would like help with this simple excersise.

    Quote Originally Posted by MrShorty View Post
    from the error statement: Your assignment statement neglects to include the "Set" keyword. Where the "Let" keyword is optional (and frequently left out) of Let statements, the Set keyword is not optional in Set statements https://msdn.microsoft.com/EN-US/lib.../gg251642.aspx

    I think it should work just fine if you include the Set keyword when you assign the range to rng
    Set rng=thisworkbook.....
    Ah, yes... that would be the right way to do things. Thank you, sir. I've seen that type of code hundreds of times here and elsewhere and simply could not see where I was going astray. Again, 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] Unable to replicate simple macro process/unable to compose simple copy paste macro
    By MattRNR in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-06-2015, 04:51 AM
  2. Replies: 4
    Last Post: 12-07-2012, 11:49 AM
  3. A simple question requiring a simple answer
    By Pedros in forum Excel General
    Replies: 3
    Last Post: 07-18-2006, 06:45 AM
  4. Simple Simple Excel usage question
    By BookerW in forum Excel General
    Replies: 1
    Last Post: 06-23-2005, 05:05 PM
  5. Make it more simple or intuitive to do simple things
    By Vernie in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 03-16-2005, 12:06 AM
  6. Posting data from a simple form to a simple database
    By clacka in forum Excel General
    Replies: 0
    Last Post: 01-30-2005, 04:37 PM

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