+ Reply to Thread
Results 1 to 3 of 3

Macro works in one workbook and not another - Run-Time Error 1004

  1. #1
    Registered User
    Join Date
    06-10-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    2

    Macro works in one workbook and not another - Run-Time Error 1004

    I am extremely new to VBA. I put together the below code to right align numbers and center align text in all sheets of a workbook. I defined the PerfArea.This code works in 3 different workbooks like a charm. In one of them I get the error message "Run-time error '1004' Method 'Range' of object'_Worksheet' failed. I don't think anything is different about this workbook. Any ideas? It looks like the problem line is the first ws.Range line. Thanks in advance.

    Please Login or Register  to view this content.
    Last edited by vrobinson; 06-10-2010 at 07:31 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro works in one workbook and not another - Run-Time Error 1004

    Possibilities:

    1) The PerfArea is not defined as you thought
    2) The ThisWorkbook references are applying the code to the wrong workbook, perhaps ActiveWorkbook would be better?
    3) There are no formulas matching the first SpecialCells test and you have no ON ERROR message above it.

    You only need one ON ERROR for that macro, and it should be directly below the For Each... code, the rest are redundant.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    06-10-2010
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Macro works in one workbook and not another - Run-Time Error 1004

    It was possibility 3. I added the ON ERROR where you indicated and removed the extra ones. Thank you!!!

    Please Login or Register  to view this content.

+ 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