+ Reply to Thread
Results 1 to 7 of 7

Macro Sheet & Formula Name Issues

Hybrid View

  1. #1
    Registered User
    Join Date
    11-17-2011
    Location
    Bishop, CA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Exclamation Macro Sheet & Formula Name Issues

    Hi All,

    I have recorded a Macro to save a coworker some time when she is going a report. The Macro functions perfectly. The problem is that the report is ran from a saved excel file from an odd program. You have to save the report to your computer, and then open it in excel and then run the macro. However whatever you save the report as, that becomes the name of the sheet that the data is stored on. So unless the report is saved as the same name each and evertime it is ran the Macro stops working because the sheet references, and formulas are referencing the name of the report I used when I recorded the macro. Is there any way to change the code to something else so that the report can be saved with any name, and the macro still work?

    Thank You
    Last edited by ZHertz; 11-17-2011 at 05:41 PM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Macro Sheet & Formula Name Issues

    Can you use the sheet's index number instead of name? Like:
    Sheets(1) instead of Sheets("Sheet1").
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Registered User
    Join Date
    11-17-2011
    Location
    Bishop, CA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Macro Sheet & Formula Name Issues

    I have tried this and it fixes the reference to the sheet name when selecting the sheets so part of my problem is fixed, thank you. But when I changed the sheet name within VBA to Sheets(1) in my formulas it does not work (I didn't expect it to, but tried anyways) but it comes up with an error highlighting the following line of my macro:

    ActiveCell.FormulaR1C1 = _
    "=SUMIF(Sheets(1)C[10],RC[-1]&"" Regular"",Sheets(1)C[2])"

    where is says "Sheets(1)" in this line was there is previously had the sheet name EX:

    ActiveCell.FormulaR1C1 = _
    "=SUMIF('Report'!C[10],RC[-1]&"" Regular"",'Report'!(1)C[2])"

    Where "Report" is the original name of the sheet.

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Macro Sheet & Formula Name Issues

    Change it to:

    ActiveCell.FormulaR1C1 = "=SUMIF(" & Sheets(1).Name & "C[10],RC[-1]&"" Regular""," & Sheets(1).Name & "C[2])"

  5. #5
    Registered User
    Join Date
    11-17-2011
    Location
    Bishop, CA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Macro Sheet & Formula Name Issues

    davegugg:
    When I paste that code into my Macro I get "Run-time error '1004': Application-defined or object-defined error, and when I click on the Debug option it highlights the portion of your Coded that I copied into my Macro over the previous one...

  6. #6
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Macro Sheet & Formula Name Issues

    ActiveCell.FormulaR1C1 = "=SUMIF('" & Sheets(1).Name & "'!C[10],RC[-1]&"" Regular"",'" & Sheets(1).Name & "'!C[2])"
    I forgot the single quotes around the sheet name and the exclamation point too.

  7. #7
    Registered User
    Join Date
    11-17-2011
    Location
    Bishop, CA
    MS-Off Ver
    Excel 2010
    Posts
    9

    Re: Macro Sheet & Formula Name Issues

    Thanks! This works perfectly again! You Rock davegugg!!!

+ 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