run-time error '91': object variable or with block variable not set

  • hi everyone,


    i'm new to excel vba and even newer to this forum so i'll appreciate any help to guide me along!



    i have a code to do the following steps:
    1) find a cell in Sheets("Phases")
    2) Reference a cell relative to it
    3) Use the fill colour (is interior.colourindex correct?) of this reference cell as a basis for comparison
    4) Move the selected cell down if the colour is the same as the reference colour



    1) currently i have a run time error. it seems that the error is at the cells.find part when i debug it. what should i do?


    2) is my code correct to compare the fill colour of a cell and then set it as a basis of comparison?


    3) also, i have another sub (not shown here) which also has "dim target as Range". is it possible to reuse the same word? or is that the cause of the error in the first place?


    *thanks to wigi for putting in code tags

  • Re: run-time error '91': object variable or with block variable not set


    Quote from kel.ley;589895

    hi everyone,


    i'm new to excel vba and even newer to this forum so i'll appreciate any help to guide me along!


    Welcome to Ozgrid.


    One of the things we ask, is to use [code] tags in your code here on the board.
    I added them for you, but please take care of this yourself.
    If not, your topics might be closed.


    Thanks.


    Wigi

    Regards,


    Wigi


    Excel MVP 2011-2014


    For more Excel memes: visit http://www.wimgielis.com ==> English articles ==> Excel memes


    -- Topics without [CODE] tags or a meaningful topic title, will be neglected by me (and probably many others as well) --

  • Re: run-time error '91': object variable or with block variable not set


    hi everyone!


    thanks for the help thus far. i've figured out the problem already.


    i was writing this piece of code in my friend's Sheet and did not know that he defined some variables under General. somehow they clashed with my portion of the code.


    just a question:


    if i used private Sub instead of Sub, will the code still have run time error if a variable (e.g. x) is declared both in General (e.g. as string) and in the private Sub(e.g. as Integer)?

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!