Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: Find Quarter Month From Date In Excel

  1. #11
    Junior Member Haseeb A's Avatar
    Join Date
    Apr 2011
    Posts
    21
    Rep Power
    0
    Firstly, I hope I am not making the thread complicated.

    ...(the less function calls, the more efficient, right?)...
    I think should be efficient. Rick, you have better knowledge & experience in all these field, so you know the things better than a less experienced guy like me .

    If we just redesign the COUPNCD function, possible to get (unless I miss something) with just one function.

    =COUPNCD(A1,"1/1/9999",4,1)-1

    If we remove the -1 gives the 1st day in the next quarter of the date in A1


    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    https://www.youtube.com/watch?v=SIDLFRkUEIo&lc=UgzTF5vvB67Zbfs9qvx4AaABAg
    https://www.youtube.com/watch?v=v_1iqtOnUMg&lc=UgxLtKj969oiIu7zNb94AaABAg
    https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugxq4JHRza_zx3sz0fx4AaABAg
    https://www.youtube.com/watch?v=f7xZivqLZxc&lc=Ugxq4JHRza_zx3sz0fx4AaABAg
    https://www.youtube.com/watch?v=f7xZivqLZxc&lc=UgzMCQUIQgrbec400jl4AaABAg
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz0Uy2bCSCTb1W-0_14AaABAg
    https://www.youtube.com/watch?v=ITI1HaFeq_g&lc=Ugx12mI-a39T41NaZ8F4AaABAg.9iDQqIP56NV9iFD0AkeeJG
    https://www.youtube.com/watch?v=vXyMScSbhk4&lc=Ugxa2VYHMWJWXA6QI294AaABAg.9irLgSdeU3r9itU7zdnW Hw
    https://www.youtube.com/watch?v=tPRv-ATUBe4&lc=UgzFkoI0n_BxwnwVMcZ4AaABAg
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugz0Uy2bCSCTb1W-0_14AaABAg.9htChVuaX9W9htG01cKBzX
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugw6UrV69zpeKvLOeOV4AaABAg.9ht16tzryC49htJ6TpIO XR
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgwMKwGZpDjv7vi7pCx4AaABAg
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=Ugw6UrV69zpeKvLOeOV4AaABAg.9ht16tzryC49htOKs4jh 3M
    https://www.youtube.com/watch?v=LuAipOW8BNQ&lc=UgxVW-am20rQ5GFuJ9F4AaABAg
    https://www.youtube.com/channel/UCnxwq2aGJRbjOo_MO54oaHA
    Last edited by DocAElstein; 10-24-2023 at 02:53 PM.

  2. #12
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    13
    Quote Originally Posted by Haseeb Avarakkan View Post
    I think should be efficient. Rick, you have better knowledge & experience in all these field, so you know the things better than a less experienced guy like me .

    If we just redesign the COUPNCD function, possible to get (unless I miss something) with just one function.

    =COUPNCD(A1,"1/1/9999",4,1)-1

    If we remove the -1 gives the 1st day in the next quarter of the date in A1
    I was a Civil Engineer during my working career, so I no know nothing about financial "things". That means I am totally unfamiliar with "coupons", but the COUPNCD function may be an exception to the efficiency rule.The first time I tried your formula, I set up a column of 14 years worth of individual days and copied your formula down in the next column over... Excel seemed to lock up. So I tried it with just one year's worth of individual days... I could watch the COUPNCD function displaying its calculated values in slow-motion down the column (which is why it looked like Excel had locked up in my initial test... the function was taking "forever" to calculate that many results). I don't know if using 1/1/9999 as a date is burdening the function down with a huge number of internal calculations or if the function (being from the Analysis ToolPak, hence, not built-in) is just a slow calculating function, but it does not look like your formula is an efficient one, at least given my test results. Can you confirm the slowness of COUPNCD when used multiple times down a column of dates?

  3. #13
    Junior Member Haseeb A's Avatar
    Join Date
    Apr 2011
    Posts
    21
    Rep Power
    0
    Yes Rick. I got the slowness in Excel 2007 too (I do not have 2003). I think it is because of 1/1/9999. When I changed the formula to,

    =COUPNCD(A1,"1/1/"&YEAR(A1)+1,4,1)-1

    and tested with 10000 cells, calculation was normal. Also, I didn't know it is a part of Analysis ToolPak in earlier versions.

  4. #14
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    13
    Quote Originally Posted by Haseeb Avarakkan View Post
    Yes Rick. I got the slowness in Excel 2007 too (I do not have 2003). I think it is because of 1/1/9999. When I changed the formula to,

    =COUPNCD(A1,"1/1/"&YEAR(A1)+1,4,1)-1

    and tested with 10000 cells, calculation was normal. Also, I didn't know it is a part of Analysis ToolPak in earlier versions.
    Okay then, we are back to two function calls for each of our formulas. Which is more efficient... I don't know. My MONTH call and your YEAR call should be equal... and both involve a single concatenation and both involve a single math operation, so they should balance out as well... so it comes down to which of LOOKUP or COUPNCD is more efficient, the answer to which I don't know. I guess, until someone who knows how to test the effeciency of these two functions and reports back here, one cannot go too wrong simply using whichever they find more comfortable.

  5. #15
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    I did a small test and the average time taken for Hasseb's and Rick's function are .22 secs and .15 secs respectively.


    Here is how I did in a blank workbook

    Code:
    Sub Haseeb()
        Dim t
        ClearAllCells
        t = Timer
        With Range("b1:b10000")
            .FormulaR1C1 = "=COUPNCD(rc[-1],""1/1/""&YEAR(rc[-1])+1,4,1)-1"
        End With
        Debug.Print Format(Timer - t, "00.00")
    End Sub
    Sub Rick()
        Dim t
        ClearAllCells
        t = Timer
        With Range("b1:b10000")
            .FormulaR1C1 = "=1*(LOOKUP(MONTH(rc[-1])+2,{3,6,9,12})&""/13"")"
        End With
        Debug.Print Format(Timer - t, "00.00")
    End Sub
    Sub ClearAllCells()
        Range("b1:b10000").ClearContents
    End Sub
    Sub FillDates()
        Range("a1") = DateSerial(1950, 1, 1)
        Range("a1:a10000").DataSeries , 3, 3
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  6. #16
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    662
    Rep Power
    13
    Okay, I guess that is a fair way to measure the time difference. My guess is the actual percentage difference between the two functions is probably larger than your numbers show because I would guess there is some "fixed" interface time between the VB world and the worksheet world that both formula assigments experience equally... subtracting that fixed time, whatever it is, from your measured time would yield the actual time to calculate the formulas themselves... the time difference you measured would not change, but the base against which it is measured would decrease making the percentage difference increase. Of course, there is no way to measure that fixed VB to worksheet interface time, so your method is in and of itself is a more than sufficient measuring tool. Thanks for coming up with it and for running the trials using it.

Similar Threads

  1. Replies: 5
    Last Post: 06-15-2013, 12:40 PM
  2. Replace Incorrect Date In Cell To Another Valid Date
    By DARSHANKmandya in forum Excel and VBA Tips and Tricks
    Replies: 2
    Last Post: 03-21-2013, 09:27 PM
  3. Automate Date Changes Within Excel Workbook
    By Danno2cu in forum Excel Help
    Replies: 9
    Last Post: 02-18-2013, 11:39 PM
  4. How To Change Date Format in Excel
    By Oh!Calcutta in forum Excel Help
    Replies: 1
    Last Post: 11-01-2012, 09:36 PM
  5. Week Of The Month
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 2
    Last Post: 02-22-2012, 08:35 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •