+ Reply to Thread
Results 1 to 13 of 13

How can this IF, OR function be improved

  1. #1
    Registered User
    Join Date
    10-13-2013
    Location
    Elgin. IL
    MS-Off Ver
    Excel 2010 & 2013
    Posts
    8

    How can this IF, OR function be improved

    Is there a better way to do this function?
    =-IF(OR(NOW()>DATE(YEAR(NOW()),9,17),(getDataFromCreditCards($A13,$B56,$C56)>-('2012'!AE13))),getDataFromCreditCards($A13,$B56,$C56),-('2012'!AE13))

    Here’s what it is doing.

    1. Checking todays date.
    2. If the date is 9/17 or greater then it gets data to fill the cell
    3. The data comes from “CreditCards” data base, using A23 (credit card name), B56 (starting date) and C56 (ending date).
    4. If the date is before 9/17 it checks last year’s input on sheet “2012” to the current data in the “CreditCards” data base and inputs the larger of the two.
    5. Also all inputs are a negative number.

    I’ve used this for over 10 years and it works but there are two annoying problems.

    1. Every year when adding a new sheet all occurrences of this need changing to the sheet it is looking at.
    2. it’s slow! With five credit cards and twelve months, that’s 60 of these checks to go through after every input.
    Last edited by targa72; 10-13-2013 at 01:20 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Is there a better way to do this function?

    Can you post the code for getDataFromCreditCards?
    If posting code please use code tags, see here.

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,050

    Re: Is there a better way to do this function?

    Please take a moment to read the forum rules and then amend your thread title to something descriptive of your problem. Once you have done this please send me a PM and I will remove this request. (Also, include a link to your thread - copy from the adress bar)

    To change a Title on your post, click EDIT POST then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Registered User
    Join Date
    10-13-2013
    Location
    Elgin. IL
    MS-Off Ver
    Excel 2010 & 2013
    Posts
    8

    Re: How can this IF, OR function be improved

    Here is the code for getDataFromCreditCards.

    Please Login or Register  to view this content.
    [B]Moderators note: code tags added for you
    Last edited by FDibbins; 10-13-2013 at 03:07 PM.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: How can this IF, OR function be improved

    What is the function meant to return, a string or numeric?

  6. #6
    Registered User
    Join Date
    10-13-2013
    Location
    Elgin. IL
    MS-Off Ver
    Excel 2010 & 2013
    Posts
    8

    Re: How can this IF, OR function be improved

    Numeric. Good catch. Don’t know why I wrote the While loop that way.

    Here’s the new and improved loop.
    Please Login or Register  to view this content.
    Moderators note: code tags added for you - this time
    Last edited by FDibbins; 10-13-2013 at 03:05 PM.

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,050

    Re: How can this IF, OR function be improved

    Targa, please use code tags when posting VBA codes. I will add them this time

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: How can this IF, OR function be improved

    targa

    If the function is to return the sum of Amount then you could use SQL's SUM function, then you wouldn't need to loop.

    That should speed things up.

  9. #9
    Registered User
    Join Date
    10-13-2013
    Location
    Elgin. IL
    MS-Off Ver
    Excel 2010 & 2013
    Posts
    8

    Re: How can this IF, OR function be improved

    Adding SUM to the SQL did not work. It was still slow and did not return a value.

    I think the problem is in the way I wrote the IF statement. If the date is before 9/17 it compares the getDataFromCreditCards to last year’s input when it should just put in last year’s cell figure. Comparing getDataFromCreditCards to last year’s input needs to take place after 9/17 only.

  10. #10
    Registered User
    Join Date
    10-13-2013
    Location
    Elgin. IL
    MS-Off Ver
    Excel 2010 & 2013
    Posts
    8

    Re: How can this IF, OR function be improved

    Adding SUM to the SQL did not work. It was still slow and did not return a value.

    I think the problem is in the way I wrote the IF statement. If the date is before 9/17 it compares the getDataFromCreditCards to last year’s input when it should just put in last year’s cell figure. Comparing getDataFromCreditCards to last year’s input needs to take place after 9/17 only.

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: How can this IF, OR function be improved

    How exactly did you try SUM in the SQL?

  12. #12
    Registered User
    Join Date
    10-13-2013
    Location
    Elgin. IL
    MS-Off Ver
    Excel 2010 & 2013
    Posts
    8

    Re: How can this IF, OR function be improved

    strSQL = "SELECT SUM (Amount) AS ReturnSet FROM tblTransactions " & _
    "INNER JOIN tblCreditCard " & _
    "ON tblCreditCard.CreditCardID = tblTransactions.CreditCardID " & _
    "WHERE CardName LIKE '%" & card_type & "%' AND " & _
    "((PostDate) >= #" & start_date & "# and (PostDate)<= #" & ending_date & "#) ;"

    rs.Open strSQL, cn
    getDataFromCreditCards = ReturnSet

  13. #13
    Registered User
    Join Date
    10-13-2013
    Location
    Elgin. IL
    MS-Off Ver
    Excel 2010 & 2013
    Posts
    8

    Re: How can this IF, OR function be improved

    Thank you Norie for your help.
    The problem was twofold, the OR part of the IF statement was forcing the getDataFromCreditCards to fire every time any cell was changed and there were to many of those IF statements. I moved all the IF statements to a separate workbook and removed the OR part and completely rewrote the IF statement.
    Now when the first workbook opens it opens the second workbook updates then saves and closes the second workbook.
    The whole workbook runs faster (except for opening) after any cell input.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] IF Function referencing IsNumber, Match, Left function on separate sheets
    By Touch9713 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-12-2013, 10:09 PM
  2. [SOLVED] Using Offset function as the array in the PercentRank function is giving wrong result
    By Bobneil in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 08-06-2013, 09:29 PM
  3. Replies: 1
    Last Post: 03-21-2012, 11:22 AM
  4. Replies: 2
    Last Post: 03-20-2009, 01:29 PM
  5. Excel - User Defined Function Error: This function takes no argume
    By BruceInCalgary in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2006, 04:05 PM

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