+ Reply to Thread
Results 1 to 24 of 24

Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

  1. #1
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Question Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    This post is related to another post that was solved but created another issue, because of my lack of thinking ahead. here is the link to the original post in case it might help..... http://www.excelforum.com/excel-prog...ing-vba-2.html

    The below code sorts data by date to find newly updated data and creates a new sheet and places the updated data into it, which works absolutely wonderfully.
    Please Login or Register  to view this content.
    Here is the part where I didn't think ahead. The sheet will be updated multiple times per day by multiple users, so the above code sends all the users updated data for the "current" day. I need it to send the updated data by the date and current user. In column B is where the current user ID/Name appears. I was provided with the code below, basically just adding the CurrentUser lines....
    Please Login or Register  to view this content.
    and now I get a "Run-time Error '91': Object variable or With block variable not set at the following line
    Please Login or Register  to view this content.
    I have tried different declarations for rngFind and current user but can't seem to get it figured out.
    If anyone has any suggestions, I will try (just about) ANYTHING at this point.

    Sorry for the long post.
    Last edited by gmr4evr1; 05-11-2015 at 07:38 PM. Reason: Corrected typo
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    Hello gmr4evr1,

    The problem is the variable CurrentUser is neither defined or assigned a value. As per the "Solved" post, you need to declare this variable and then assign it a value.

    You mentioned you have the a list of users names. I believe it was in column "B". Are these names the logon user names ? If so you can retrieve the name of the current user this way...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    Howdy Leith,

    Thanks for your suggestion. I have tried adding it to my existing code that is posted above and I am still getting the same error on the same line. So, most likely, I am not doing something right somewhere, but, I have no idea what or where.

    Yes, the user names are logon user names and they are placed in column "B" with a separate function. Here is the code for the function that is in a separate module and does work...
    Please Login or Register  to view this content.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    Hello gmr4evr1,

    You don't need a separate function. The code should be added to Macro1. The code below has the changes added.
    Please Login or Register  to view this content.

  5. #5
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    Leith,

    Thank you again for your help. The way you have the code written above is exactly the way I tried the first few times and was still getting the error. I even "deactivated" the function code just in case it was causing the issue, but it still didn't work. So this time I copied and pasted the code you provided with the changes, and guess what.....I still get the same error @ the same line

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    You will get the error you describe here if rngFind is Nothing.
    Please Login or Register  to view this content.
    That's because you are trying to find the Row of Nothing.

    Try separating the If statement out.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  7. #7
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    Norie,

    Thank you for your input, while that did take care of the original reason for this post, I am now faced with another issue....UGH!

    Norie/Leith,

    When it loops back through the code, it starts at the beginning and tries to create another sheet with the date. Of course it errors at that point because you cannot have two worksheets with the same name. How can I get it to start the loop after the headings part of the code?

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    What is the code meant to do?

  9. #9
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    Its meant to create a new sheet with the current days date as the name of the sheet, look in column "A" and find the "NOW" date, then look in column "B" and find current user (logon) name, then copy and paste the rows that meet that criteria to the newly created sheet. The only thing it does so far, is create the sheet and name it the current date, then loops back through and tries to create another sheet. It doesn't copy/paste any of the data.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    Have you considered using a filter and copying the results to the new sheet rather than looping?

  11. #11
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    I have not, I don't know enough about VBA to go about doing this. The code I am using was provided to me by another forum member, you and Leith have helped me edit it to get to the point we are at now. The reason I am trying to do this is that the "master" sheet is added to daily, at least twice a day by different users. Once they have finished updating it, they click a button and it automatically sends an email, among other things. The problem was that the email contained everything in the master sheet, and I need it to send the updated portion only. Hence, the code I am trying to use now, it is supposed to create another sheet, with the updated info only, then email the newly created sheet. Everything, other than the users updating the info is to be automated, so there will be no actual user selecting anything for the email, the code will (well, is supposed to) do that for them.

  12. #12
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    Ok, while stepping through the code I noticed that when it gets to
    Please Login or Register  to view this content.
    the code skips to the second End IF and never looks at the rest of the code between
    Please Login or Register  to view this content.
    IS it finding "nothing" and that is why it is skipping, or, did I mess something up with the code?

  13. #13
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    Hello gmr4evr1,,

    Yes, you correct. The object rngFind was set to the special object Nothing. If it had been successful then it would have returned a Range object.

  14. #14
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    I'm going to be honest, this code just isn't right.

    I think we need to see a workbook with before/after data.

  15. #15
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    EOSR Sample For EF.xlsm
    Norie,
    Ok, here is an updated version of my before/after that was posted in the other thread. The "Before" tab is the "master" sheet, but it is also what is being emailed when the "save, close and email" button is clicked. The "After" tab is what I want it to email. The tab with the date on it is the one that the code I am having a problem with is creating, its not listing the updated information. The code in question is in Module 2. There is other code being used as well, but the module 2 code is where the issue is. It is supposed to create the new sheet based on the "Now" date in column A, AND the CurrentUser that is logged on in Column B.
    Last edited by gmr4evr1; 05-17-2015 at 10:42 AM. Reason: Added Info

  16. #16
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    Quote Originally Posted by Leith Ross View Post
    Hello gmr4evr1,,

    Yes, you correct. The object rngFind was set to the special object Nothing. If it had been successful then it would have returned a Range object.
    Leith,

    I understand what you are saying, what I don't understand is what the range is that it is "looking" for. I thought the range was A1 since it's looking at .Cells(1, 1). If this is correct, then it should find a date there....or am I just way off base with my thought process?

  17. #17
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    Any more info on, or luck with this?

  18. #18
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    Norie, Leith, Anyone have a way to do what I am trying to do? Or should I start another post?

  19. #19
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    Hello gmr4evr1,

    I had to make a lot of changes to your macro to get to work. The macro as it is now is shown below and has been added to the attached workbook.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  20. #20
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    THANK YOU Leith!!!!!!! IT WORKS, it works, it works!!!! Man, I have been at this for far too long and you have given me a solution and I greatly appreciate it. Once I figure out how to give as much rep as I want, I will give you oodles and gobs of it!! Thank you again!!

  21. #21
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    Hello gmr4evr1,

    You're welcome. Glad I could help out.

  22. #22
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    Leith,

    Bad news.....The code is sorting by CurrentUser as I wanted, but the other "sort" I was looking for was for it to sort by the current date (TODAY) as well. So, it looks in column A for todays date, then column B for the current username and places only that data on the new sheet. When I ran it today, it put everything for the current user on the new sheet, including data from yesterdays date.

  23. #23
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    Hello Hello gmr4evr1,

    Sorry about that. Just needs a small addition to make that happen. It is marked in blue.
    Please Login or Register  to view this content.

  24. #24
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: Why am I Getting a Run-time Error '91' error after adding CurrentUser to code below?

    Leith,
    Brilliant! Thanks again....I think we (YOU) got it this time.

+ 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. Need to add if error code to worksheet change event to stop a run-time error
    By KT99 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-18-2014, 03:10 PM
  2. [SOLVED] Run-Time Error '13' could someone look at this code for a error please
    By Mr_Bill in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 09-01-2014, 07:48 PM
  3. Replies: 4
    Last Post: 11-15-2013, 05:03 PM
  4. VBA Code...error = run time error 1004 autofilter method of range class failed
    By Dariusd7 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-15-2013, 04:49 PM
  5. Error "run-time Error '1004': General Odbc Error
    By D4WNO77 in forum Access Tables & Databases
    Replies: 2
    Last Post: 07-16-2012, 09:55 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