+ Reply to Thread
Results 1 to 12 of 12

Trouble Running IF Statement while recording Macro

  1. #1
    Registered User
    Join Date
    08-11-2011
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2003
    Posts
    7

    Trouble Running IF Statement while recording Macro

    I'm trying to enter an IF statement while recording a macro, and normally this wouldn't be a problem. But with this particular IF statement, an error ("Unable to record in macro")comes up right after I push the "Enter" after writing in the statement. After I'm recording the Macro, I notice there is no IF statement in the actual VBA code.

    Here's the IF statement:

    =IF(AND(OR(D2="500 Account",D2="055 Account"),OR(LEFT(B2,2)="LT",B2="** Investment Intraco",B2="Fed Funds Purch Account",B2="Fed Funds Account")),1/0,IF(OR(D2="500 Account",D2="055 Account"),1,1/0))

    Can anyone see why this particular IF statement would cause a problem while recording the macro?

    Thanks in advance...

  2. #2
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Trouble Running IF Statement while recording Macro

    Sounds to me like your current Excel session is having challenges. Save changes if needed, then shut down all instances of Excel and start fresh. Let me know if that does the trick.
    If your question has been satisfactorily addressed, please consider marking it solved. Click the Thread Tools dropdown and select Mark thread as solved.
    Also, you might want to add to the user's reputation by clicking the star icon in the lower left corner of the post with the answer- it's why we do what we do...

    Thomas Lafferty
    Analyst/Programmer

  3. #3
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,935

    Re: Trouble Running IF Statement while recording Macro

    You have two :1/0 ELSE clauses in your formula. Division by zero is never allowed and results in a #DIV/0! error.
    Ben Van Johnson

  4. #4
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Trouble Running IF Statement while recording Macro

    protonLeah is correct about the divide by zero error, however I'm still able to record a macro which writes the formula in a VBA module. The user probably has an Excel session which has gone wonky and just needs to restart it.

  5. #5
    Registered User
    Join Date
    08-11-2011
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Trouble Running IF Statement while recording Macro

    Quote Originally Posted by tlafferty View Post
    protonLeah is correct about the divide by zero error, however I'm still able to record a macro which writes the formula in a VBA module. The user probably has an Excel session which has gone wonky and just needs to restart it.
    I have already restarted my computer and it yields the same result. Also, I actually want it to show an error as part of the process. So the 1/0 is fine.

    Any other ideas? thanks

  6. #6
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Trouble Running IF Statement while recording Macro

    If I understand you correctly, when you attempt to record, it creates a module, but doesn't record the creation of the formula?

    Will Excel record other macros? For instance, start the recorder, select A1 and type your name and press enter. Does it record that? If not, you may need to run detect and repair on office.

  7. #7
    Registered User
    Join Date
    08-11-2011
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Trouble Running IF Statement while recording Macro

    Quote Originally Posted by tlafferty View Post
    If I understand you correctly, when you attempt to record, it creates a module, but doesn't record the creation of the formula?

    Will Excel record other macros? For instance, start the recorder, select A1 and type your name and press enter. Does it record that? If not, you may need to run detect and repair on office.
    It's odd, but records other macros just fine. It's like there is something with this equation that makes the macro bug out. I'm hoping I don't have to re-write it.

    EDIT: But there really is nothing wrong with the equation. I've run it without recording a macro, and it runs fine.
    Last edited by MacroNovice; 08-12-2011 at 04:36 PM.

  8. #8
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Trouble Running IF Statement while recording Macro

    Can you attach your book and let me try it?

  9. #9
    Registered User
    Join Date
    08-11-2011
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Trouble Running IF Statement while recording Macro

    I've attached a dummy workbook (titled Test Equation). I can't share the original file because of the information involved.

    But below the yellow highlighted cell you will be able to see the equation.

    A little background: The reason I want to make the cells an error is so that I can delete all rows which contain certain values. So, in the case of the dummy workbook, I would WANT to delete all rows which include "LT", "**", "Fed Funds Purch", "Fed Funds Term" in column B. OR, any other value in column D besides "YY" and "YY5" should warrent the row to be deleted.

    I'm using errors so that I can EDIT-GO TO-SEPCIAL-ERRORS and then EDIT-DELETE-ENTIRE ROW.
    Attached Files Attached Files

  10. #10
    Valued Forum Contributor tlafferty's Avatar
    Join Date
    04-08-2011
    Location
    United States, Tacoma, WA
    MS-Off Ver
    Excel 2010, Excel 2013 Customer Preview
    Posts
    1,112

    Re: Trouble Running IF Statement while recording Macro

    Try this code instead:
    Please Login or Register  to view this content.
    This will locate and delete any row matching the criteria you specified. The case selection refers to column numbers, so if you wanted to examine column C or E, add criteria to case 3 and 5.

  11. #11
    Registered User
    Join Date
    08-11-2011
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Trouble Running IF Statement while recording Macro

    Quote Originally Posted by tlafferty View Post
    Try this code instead:
    Please Login or Register  to view this content.
    This will locate and delete any row matching the criteria you specified. The case selection refers to column numbers, so if you wanted to examine column C or E, add criteria to case 3 and 5.
    Thanks for the code... I'm really new to VBA, so I have a couple questions.

    - Can I record the macro, exluding this step, and then simply input this code into the recorded macro where I want it? If so, do I need to make any alterations prior to inserting this code?

    - Why is "Case Is = 5" located after the other "Case Is" statements?

    Thanks

  12. #12
    Registered User
    Join Date
    08-11-2011
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2003
    Posts
    7

    Re: Trouble Running IF Statement while recording Macro

    Bump... Anyone got an answer to that last question?

+ 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