Consulting

Results 1 to 6 of 6

Thread: Run-Time error '91' Object variable or With variable not set

  1. #1
    VBAX Regular
    Joined
    Jan 2019
    Posts
    6
    Location

    Run-Time error '91' Object variable or With variable not set

    Hi Friends,

    I have a problem on a simple code. I hope you can help me. I am getting Run-Time error '91' error.
    Thank you. Please see attached file.

    Regards
    Attached Files Attached Files

  2. #2
    Funny thing is, if you set it to lookin xlFormulas, it seems to work.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    1. The 'real' value in J2 is 43999 since Excel stores dates as serial numbers so that's why xlFormulas works

    2. You Dim MyDate as a Date, but assign a string so Excel nicely (?) converts it for you

    3. You have Custom Number formatting on row 2 (dd-mmm-yy) so I think .Find returns Nothing if you don't give it a string it can locate

    4. The Worksheets(I).Rows(2).Nothing is likely what causes the Error 91 since it doesn't have a .Column


    Dim MyDate As Date    '   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    
    
    'MyDate = "2019-05-14"
    
    MyDate = DateSerial(2019, 5, 14)    '   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    'MyDate = Application.inputbox("Put Date:", "Choose Date")
    
    'two ways <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    
    Colx = Worksheets(i).Rows(2).Find(what:=Format(MyDate, "dd-mmm-yy"), LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False).Column
    
    or
    
    Colx = Worksheets(i).Rows(2).Find(what:=MyDate, LookIn:=xlFormulas, lookat:=xlWhole, MatchCase:=False).Column ' Define Column
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  4. #4
    VBAX Regular
    Joined
    Jan 2019
    Posts
    6
    Location
    Thank you Paul,

    You are right, it was problem of DIM Type. It is solved.

    Regards

  5. #5
    VBAX Regular
    Joined
    Jan 2019
    Posts
    6
    Location
    How can I change the position of this post as "SOLVED". I did not find it ...

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    #3 in my signature
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •