+ Reply to Thread
Results 1 to 13 of 13

Thread: Recorded macro gets formula error

  1. #1
    Registered User
    Join Date
    09-30-2010
    Location
    Minnesota, USA
    MS-Off Ver
    Excel 2010
    Posts
    54

    Recorded macro gets formula error

    I Recorded a Macro and when I test what I Recorded Macro, I get a “run-time error ‘1004’: Application-defined or object-defined error” asking if I want to debug or End, I click debug and it highlights the Active Cell Formula, why

    This is the original Formula that was entered in the Cell.
    =IF(T21="Yes","show",IF(IF(D21*1>=$D$15,IF(D21*1<=$D$16,IF((INDEX(Alignment_Reports,ROW()-20,COLUMN()+$R$10))*1>=$E$16,IF((INDEX(Alignment_Reports,ROW()-20,COLUMN()+$R$10))*1<=$F$16,"show","offset too high"),"offset too low"),"stationing too high"),"stationing too low")="show",IF(S21="Storm","show",IF(S21="Sanitary","Sanitary","not Sewer")),"Don't Show"))

    
    Sub Macro24()
    '
    ' Macro24 Macro
    '
    
    '
        Range("R21").Select
        ActiveCell.FormulaR1C1 = _
            "=IF(RC[2]=""Yes"",""show"",IF(IF(RC[-14]*1>=R15C4,IF(RC[-14]*1<=R16C4,IF((INDEX(Alignment_Reports,ROW()-20,COLUMN()+R10C18))*1>=R16C5,IF((INDEX(Alignment_Reports,ROW()-20,COLUMN()+R10C18))*1<=R16C6,""show"",""offset too high""),""offset too low""),""stationing too high""),""stationing too low"")=""show"",IF(RC[1]=""Storm"",""show"",IF(RC[1]=""Sanitary"",""Sanitary""" & _
            "ewer"")),""Don't Show""))"
        Range("R21").Select
        Selection.Copy
        Range("R22").Select
        Range(Selection, Selection.End(xlDown)).Select
        ActiveSheet.Paste
        Application.Goto Reference:="Print_Area"
    End Sub
    Last edited by CityMPLSEmpolyee; 02-09-2012 at 08:55 AM.

  2. #2
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,228

    Re: Recored macro gets formula error

    Try this:
    Sub AddFormula()
    Dim LR As Long
    
    LR = Range("R" & Rows.Count).End(xlUp).Row
    
    Range("R21:R" & LR).FormulaR1C1 = "=IF(RC[2]=""Yes"",""show"",IF(IF(RC[-14]*1>=R15C4,IF(RC[-14]*1<=R16C4,IF((INDEX(Alignment_Reports,ROW()-20,COLUMN()+R10C18))*1>=R16C5,IF((INDEX(Alignment_Reports,ROW()-20,COLUMN()+R10C18))*1<=R16C6,""show"",""offset too high""),""offset too low""),""stationing too high""),""stationing too low"")=""show"",IF(RC[1]=""Storm"",""show"",IF(RC[1]=""Sanitary"",""Sanitary""" & "ewer"")),""Don't Show""))"
        
    Application.Goto Reference:="Print_Area"
    End Sub
    _________________
    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
    09-30-2010
    Location
    Minnesota, USA
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: Recored macro gets formula error

    Thanks JBeaucire
    but I get the same error

  4. #4
    Registered User
    Join Date
    09-30-2010
    Location
    Minnesota, USA
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: Recored macro gets formula error

    I would also like to note that in the recoreding of the macro it deletes part of the formula
    at the end you should see "not Sewer")),"Don't Show"))
    but the recording gets "ewer")),"Don't Show"))

  5. #5
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,228

    Re: Recorded macro gets formula error

    Time to post a workbook with verbal description of the logic to evaluate in the order of importance. Click GO ADVANCED and use the paperclip icon to post up a copy of your workbook.
    _________________
    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!)

  6. #6
    Registered User
    Join Date
    09-30-2010
    Location
    Minnesota, USA
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: Recorded macro gets formula error

    These are the two functions that are not working for me.
    See attached file.
    
    Sub Filter_Sanitary()
                    MsgBox "Add Sanitary Formula at Range R21:R420"
        Range("R21:R420").Select
        ActiveCell.FormulaR1C1 = _
            "=IF(RC[2]=""Yes"",""show"",IF(IF(RC[-14]*1>=R15C4,IF(RC[-14]*1<=R16C4,IF((INDEX(Alignment_Reports,ROW()-20,COLUMN()+R10C18))*1>=R16C5,IF((INDEX(Alignment_Reports,ROW()-20,COLUMN()+R10C18))*1<=R16C6,""show"",""offset too high""),""offset too low""),""stationing too high""),""stationing too low"")=""show"",IF(RC[1]=""Storm"",""show"",IF(RC[1]=""Sanitary"",""Sanitary""," & _
            ",""Don't Show""))"
    End Sub
    Sub Filter_Storm()
    '                MsgBox "Add Storm Formula at Range R21:R420"
        Range("R21").Select
        ActiveCell.FormulaR1C1 = """=IF(T21=""Yes"",""show"",IF(IF(D21*1>=$D$15,IF(D21*1<=$D$16,IF((INDEX(Alignment_Reports,ROW()-20,COLUMN()+$R$10))*1>=$E$16,IF((INDEX(Alignment_Reports,ROW()-20,COLUMN()+$R$10))*1<=$F$16,""show"",""offset too high""),""offset too low""),""stationing too high""),""stationing too low"")=""show"",IF(S21=""Storm"",""show"",IF(S21=""Sanitary"",""Sanitary"",""not Sewer"")),""Don't Show""))"""
        Selection.Copy
        Range("R21:R420").Select
        ActiveSheet.Paste
    End Sub
    I am also work on a macro that will identify if a button has been deleted or not (see if then statement). And the above code will be called into that as will. So note I am still working on other parts of the workbook, but most of it is done.
    See macro named "Make_New_Plan_Sheet_Tab", all this you can find in module "Module04_template"

    Thanks for your help.
    Attached Files Attached Files
    Last edited by CityMPLSEmpolyee; 02-07-2012 at 08:44 AM.

  7. #7
    Registered User
    Join Date
    09-30-2010
    Location
    Minnesota, USA
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: Recorded macro gets formula error

    question, could may formula be to long (is there a limit in macros )?

  8. #8
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,228

    Re: Recorded macro gets formula error

    Switch from the FormulaR1C1 syntax to just the Formula syntax and enter the formula into the entire range all at once using the formula for R21 as the formula basis:

    Sub Filter_Sanitary()
        MsgBox "Add Sanitary Formula at Range R21:R420"
        Range("R21:R420").Formula = "=IF(T21=""Yes"",""show"",IF(IF(D21*1>=$D$15,IF(D21*1<=$D$16,IF((INDEX(Alignment_Reports,ROW()-20,COLUMN()+$R$10))*1>=$E$16,IF((INDEX(Alignment_Reports,ROW()-20,COLUMN()+$R$10))*1<=$F$16,""show"",""offset too high""),""offset too low""),""stationing too high""),""stationing too low"")=""show"",IF(S21=""Storm"",""show"",IF(S21=""Sanitary"",""Sanitary"",""not Sewer"")),""Don't Show""))"
    End Sub

    Wrapping lines of code is meant for your own sanity, it isn't required.
    _________________
    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!)

  9. #9
    Registered User
    Join Date
    09-30-2010
    Location
    Minnesota, USA
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: Recorded macro gets formula error

    Thank you very much,
    That works great.

    Your help and everyone else at this forum are great help.
    I don't know what I’d do without it, Thanks

    I read the other threads just to get ideas

  10. #10
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    19,228

    Re: Recorded macro gets formula error

    You should get out of the habit of selecting, just send your commands directly to sheets/cells. Here are some example excerpts from your workbook that can be slimmed down as shown:

    'Clear out unwanted Data
        Range("GB15:GI" & Rows.Count).ClearContents
    
    
    
    'Copping data at temporary location
        Range("HB15").CurrentRegion.Copy
    
    
    
    'Clearing data at temporary location
        Range("HB:HI").ClearContents
    
    
    
    'Copping calulated data for pasting
        Range("A15").Value = Range("A14").Value
    
    
    'Sub New_worksheet_Sanitary()
         Range("B18").Value = "SANITARY SEWER STRUCTURES"
    
    
    
        With Range("B18:O18").Font
            .ColorIndex = xlAutomatic
            .TintAndShade = 0
        End With
    _________________
    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!)

  11. #11
    Registered User
    Join Date
    09-30-2010
    Location
    Minnesota, USA
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: Recorded macro gets formula error

    I applied must of your suggestions, but the original error came back
    I’m attaching a test file for your reference. And I am including some sample drainage Report files. I will add the Alignment Clearance Reports in another Reply

    Sub Filter_Storm()
    
    'UnProtecting ActiveSheet with password
        Call UnProtectSheet
    
        Range("R21:R420").Formula = "=IF(B21=0,"",IF(T21=""Yes"",""show"",IF(IF(D21*1>=$D$15,IF(D21*1<=$D$16,IF((INDEX(Alignment_Reports,ROW()-20,COLUMN()+$R$10))*1>=$E$16,IF((INDEX(Alignment_Reports,ROW()-20,COLUMN()+$R$10))*1<=$F$16,""show"",""offset too high""),""offset too low""),""stationing too high""),""stationing too low"")=""show"",IF(S21=""Storm"",""show"",IF(S21=""Sanitary"",""Sanitary"",""not Sewer"")),""Don't Show"")))"
        
    'Protecting ActiveSheet with password
        Call ProtectSheet
    
    End Sub
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    09-30-2010
    Location
    Minnesota, USA
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: Recorded macro gets formula error

    The up-loader program for the Forum can’t see the Alignment Clearance Report file as they are created (html format). So I saved them to text files so that you could see the data, but they won’t work as they are, I edited Alignment A so it would be easier to read, the others are as is from the html file. I hope this helps those how are helping or trying to learn from this,
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    09-30-2010
    Location
    Minnesota, USA
    MS-Off Ver
    Excel 2010
    Posts
    54

    Re: Recorded macro gets formula error

    I am hoping that someone will review the code again. I am still getting the error.

+ 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.2.0