+ Reply to Thread
Results 1 to 3 of 3

run time error 91 - but code works in another spreadsheet ?

  1. #1
    Registered User
    Join Date
    05-07-2013
    Location
    a, England
    MS-Off Ver
    Excel 2007
    Posts
    3

    run time error 91 - but code works in another spreadsheet ?

    I'm new and any help appreciated ,the code below works fine in one spreadsheet but not in the one I need it to ! I get run time error 91- object variable or with block variable not set?

    The aim is to find the given date in cell E2 in row 5

    'Finddate Macro
    Sub Finddate()
    Dim MyDate As String
    WorkSheets("Sheet1").Select
    Range("E2").Select
    MyDate = Format(ActiveCell.Value, "ddd-dd-mmm-yyyy")
    WorkSheets("Sheet1").Rows(5).Find(What:=MyDate, LookIn:=xlValues).Activate
    Application.Goto Selection, True

    End Sub

  2. #2
    Registered User
    Join Date
    05-07-2013
    Location
    a, England
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: run time error 91 - but code works in another spreadsheet ?

    Through a process of elimination I found that:

    1/ the cell formats of the selected cell (E2) and the cell found have to be nearly identical, the difference was that in the found cell I had made the horizontal alignment 'centre across selection' and this resulted in an error, cell E2 was left indent
    2/ even when the cell alignments were equal if the found cell was not wide enough to display it's date ie it appeared on screen as '#####' then this also resulted in an error, I got round this by reducing the font size (despite this alse being a difference in format!)

    No idea why this happens ?

  3. #3
    Registered User
    Join Date
    05-07-2013
    Location
    a, England
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: run time error 91 - but code works in another spreadsheet ?

    Through a process of elimination I found that:

    1/ the cell formats of the selected cell (E2) and the cell found have to be nearly identical, the difference was that in the found cell I had made the horizontal alignment 'centre across selection' and this resulted in an error, cell E2 was left indent
    2/ even when the cell alignments were equal if the found cell was not wide enough to display it's date ie it appeared on screen as '#####' then this also resulted in an error, I got round this by reducing the font size (despite this alse being a difference in format!)

    No idea why this happens ?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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