+ Reply to Thread
Results 1 to 9 of 9

Translating array formula - count unique values between dates on filtered sheet - to VBA

  1. #1
    Forum Contributor
    Join Date
    10-08-2013
    Location
    London
    MS-Off Ver
    365
    Posts
    138

    Translating array formula - count unique values between dates on filtered sheet - to VBA

    Hi All,

    63falcondude was kind enough to assist me with a formula to count unique values between dates on filtered sheet here:https://www.excelforum.com/excel-for...red-sheet.html and I thought I would be able to easily translate the formula into VBA as I have done many times. Unfortunately, this one has got the better of me! The original, working formula looks like this:

    {=SUM(IF(FREQUENCY(IF(SUBTOTAL(103,OFFSET(C9,ROW(C9:C15)-ROW(C9),,1)),IF((D9:D15>=D2)*(D9:D15<=D3),MATCH("~"&C9:C15,C9:C15&"",0))),ROW(C9:C15)-ROW(C9)+1),1))}

    My best effort to translate to VBA looks like this:
    Please Login or Register  to view this content.
    When the code gets to here, I get an "Unable to set the FormulaArray property of the Range class" error. I thought it had something to do with the number of quotation marks where quotation marks are required in the formula but no matter what combination I try, I keep getting the error. I thought I knew the syntax for this but clearly I don't or there is another issue I'm missing. I'm using the LastRow + 8 variable in other formulas in the code just above this line that work just fine.

    Any help would be appreciated.

    Many thanks,
    Dave C

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Translating array formula - count unique values between dates on filtered sheet - to V

    This is from the Remarks section for the .FormulaArray help screen.

    Remarks
    If you use this property to enter an array formula, the formula must use the R1C1 reference style, not the A1 reference style (see the second example).
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Contributor
    Join Date
    10-08-2013
    Location
    London
    MS-Off Ver
    365
    Posts
    138

    Re: Translating array formula - count unique values between dates on filtered sheet - to V

    Hi AlphaFrog, thanks for the reply.

    I'm still confused as I have used the following code in the same macro that works and applies the array formula to the worksheet:
    Please Login or Register  to view this content.
    Is there a function or character in my query formula that is different that would cause the error? It would be good to know why one line of similar code works and not the other.

    Many thanks,

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Translating array formula - count unique values between dates on filtered sheet - to V

    It works if you apply it using just .Formula
    So I would guess the syntax is correct.

    I don't know the problem is. Perhaps it currently evaluates to an error? Just a another guess.

  5. #5
    Forum Contributor
    Join Date
    10-08-2013
    Location
    London
    MS-Off Ver
    365
    Posts
    138

    Re: Translating array formula - count unique values between dates on filtered sheet - to V

    Odd behavior. When I add as .Formula, exit the macro and manually CTRL + SHIFT + ENTER, the formula converts to an array and works perfectly. I've now even tried converting the formula to an array in a second line:
    Please Login or Register  to view this content.
    The first line inserts the formula just fine but the second gets the error.

    Untitled.png

    Does anyone know how I might add this array formula to my worksheet?

    Many thanks,

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,659

    Re: Translating array formula - count unique values between dates on filtered sheet - to V

    For what it's worth, it sucsessfully appies the FormulaArray using the R1C1 reference style

  7. #7
    Forum Contributor
    Join Date
    10-08-2013
    Location
    London
    MS-Off Ver
    365
    Posts
    138

    Re: Translating array formula - count unique values between dates on filtered sheet - to V

    Have worked this out now. Yes R1C1 reference style does work, I just needed to learn more about it. My understanding of R1C1 is much better now!

    Thanks for your assistance AlphaFrog.

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2509 (Windows 11 Home 24H2 64-bit)
    Posts
    92,376

    Re: Translating array formula - count unique values between dates on filtered sheet - to V

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  9. #9
    Forum Contributor
    Join Date
    10-08-2013
    Location
    London
    MS-Off Ver
    365
    Posts
    138

    Re: Translating array formula - count unique values between dates on filtered sheet - to V

    Oops. Meant to do that! Thanks AliGW.

+ 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] Count unique values between dates on filtered sheet
    By L plates in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-25-2018, 05:29 AM
  2. [SOLVED] SUMIF array formula to count unique values after a certain date
    By CakeMish in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-13-2015, 09:24 AM
  3. [SOLVED] Count unique values based on criteria but without array formula (CSE)
    By Villalobos in forum Excel General
    Replies: 3
    Last Post: 05-09-2015, 05:05 AM
  4. [SOLVED] Macro to count unique values in a column with pop up message box - sheet will be filtered
    By excel151515 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-27-2014, 10:53 AM
  5. [SOLVED] Count number of unique names in a filtered list (non array)
    By IN_FOR_SIN in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 01-31-2014, 04:07 AM
  6. Formula to COUNT UNIQUE Values BETWEEN given dates
    By wantutri in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-09-2013, 12:09 PM
  7. [SOLVED] Count unique values in list but NOT using ARRAY formula
    By alx0101 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 03-15-2013, 08:15 AM

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