+ Reply to Thread
Results 1 to 5 of 5

Set variable shows runtime error 91 when using found item

  1. #1
    Registered User
    Join Date
    01-06-2022
    Location
    England
    MS-Off Ver
    Office 365
    Posts
    3

    Question Set variable shows runtime error 91 when using found item

    Hi,

    I am trying to find an offset date from a table, using a range reference in another sheet. This found offset is to then be copied across into another table when a new working week is needed in the spreadsheet.
    I had this working last night after solving the issue but it keeps rearing its ugly head.

    here is the code I have...

    Sub Roll_JCHR()
    Call SetListObjects
    'JCHR Project Data Roll and Adjustments...
    'Data Within Table...
    With JCHRProject.DataBodyRange.Columns(2).Resize(, 5).Copy
    JCHRProject.DataBodyRange.Columns(1).PasteSpecial
    JCHRProject.DataBodyRange.Columns(6).Clear
    'Header Titles for Project Utilisation...
    JCHRProject.HeaderRowRange(2).Resize(, 5).Copy
    JCHRProject.HeaderRowRange(1).PasteSpecial
    End With
    'Copy New Date Into "Week 6" of Table...
    wsDataInput.Activate
    Dim WeekStartDate As Range
    Set WeekStartDate = ProjectDates.DataBodyRange.Columns(2).Find(what:=wsResource.Range("C3").Value)
    Dim RollDate As Range
    Set RollDate = WeekStartDate.Offset(5, 0)
    RollDate.Copy
    JCHRProject.HeaderRowRange(6).PasteSpecial xlPasteValues
    wsResource.Activate
    'Adjust Remaining Tables Under Employee...
    With JCHRPropose.DataBodyRange.Columns(2).Resize(, 5).Copy
    JCHRPropose.DataBodyRange.Columns(1).PasteSpecial
    JCHRPropose.DataBodyRange.Columns(6).Clear

    JCHRMisc.DataBodyRange.Columns(2).Resize(, 5).Copy
    JCHRMisc.DataBodyRange.Columns(1).PasteSpecial
    JCHRMisc.DataBodyRange.Columns(6).Clear

    JCHRProject.HeaderRowRange.Copy
    JCHRPropose.HeaderRowRange(1).PasteSpecial
    JCHRMisc.HeaderRowRange(1).PasteSpecial
    End With

    it throws the error when it is setting the RollDate.

    Any help would be great.

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,972

    Re: Set variable shows runtime error 91 when using found item

    The error means that the Find didn't return anything. You should always test if WeekStartDate is Nothing before you try to use it.

    Also note that the various optional Find parameters persist between uses - both code and UI uses - so you should really specify them all to be sure you are doing the find you actually want.
    Everyone who confuses correlation and causation ends up dead.

  3. #3
    Registered User
    Join Date
    01-06-2022
    Location
    England
    MS-Off Ver
    Office 365
    Posts
    3

    Re: Set variable shows runtime error 91 when using found item

    I have added to the find parameters that I want it to look in xlValues. It seems to be working now, but I'm confused as to why I had it working last night?
    I will keep an eye on this once I start adding the routine to other tables. Once it is all okay I will change to solved.

    Thank you for your help.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,972

    Re: Set variable shows runtime error 91 when using found item

    As I said, all the optional parameters persist. So if you had run another find, either manually or in code, that used a parameter that wouldn't match your current search (eg matchcase), it would stop your find from working.

  5. #5
    Registered User
    Join Date
    01-06-2022
    Location
    England
    MS-Off Ver
    Office 365
    Posts
    3

    Re: Set variable shows runtime error 91 when using found item

    Hello, All is well with the spreadsheet, the additional terms in the Find have made it work nicely.
    After watching some more videos on the subject, I see what you mean. I thought as I was only using the find function for locating the date in a single table it would have worked.

    Again, thank you for helping.

+ 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] Public variable and Runtime error 91: Object Variable or With block variable not set
    By Frank Nunez in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 10-31-2020, 04:02 PM
  2. Runtime Error 76 - Path not Found
    By elisas in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-19-2018, 10:11 AM
  3. runtime error '-2147024809 (80070057)' The item with the specified name wasn't found
    By jigarrathod in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-05-2017, 09:18 PM
  4. Runtime error '53': File not found
    By blindbeggar in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-12-2016, 04:09 AM
  5. If Runtime error Shows up then Give a Msgbox (for userform)
    By ohboyherewegoagain in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-17-2014, 09:20 AM
  6. [SOLVED] Variable not found & Runtime error 13
    By DJvdW in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-08-2013, 08:17 AM
  7. Replies: 1
    Last Post: 11-17-2012, 11:10 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