Consulting

Results 1 to 4 of 4

Thread: Updating macro to Excel 2010

  1. #1

    Updating macro to Excel 2010

    I have a macro which was developed in Excel 2007 (version 12.0?). When I run it in Excel 2010 (version 14.0), I get some inconsistent errors as follows:

    I have this code operating on one worksheet:
    [vba]
    Range("A1").Select
    ActiveSheet.Paste
    [/vba] which is acceptable. A little later, I have, operating on a different worksheet:
    [vba]
    Range("A6").Select
    ActiveSheet.Paste
    [/vba] which gives a run-time error '1004': Paste method of Worksheet class failed.

    Commenting that statement out and running again. I have this code:
    [vba]
    Cells.Find(What:="3", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
    xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False) _
    .Activate
    [/vba]
    which runs OK. A few lines further on:
    [vba]
    Cells.Find(What:="6", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
    xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False) _
    .Activate
    [/vba] fails with a run-time error '91': Object variable or width block variable not set.

    What's happening and how do I fix it? These appear to be the only sources of run-time error.

    I'm running the macro in Windows 7 on an ASUS Eee Slate. I can't test it anywhere else.

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    There is nothing wrong with the code per se. It does not check for scenarios where it might fail though. How does it handle pasting when some cells might be protected on a protect sheet and workbook? How can it activate a found cell if it was not found. You need to set the find to a range object and then check if it is not Nothing before activating the set range.

  3. #3
    Using the same source data, the code runs well in Excel 2007 and fails in Excel 2010. My problem is that two identical commands are accepted on their first encounter by VBA and rejected on their next encounter. How and why?

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    I would suggest that you make a short example xlsm and post it.

Posting Permissions

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