+ Reply to Thread
Results 1 to 3 of 3

R1C1 Formula for subtotal

  1. #1
    Registered User
    Join Date
    12-10-2012
    Location
    Canada
    MS-Off Ver
    Microsoft Excel: Mac 2011 & Microsoft Excel 2010
    Posts
    13

    Unhappy R1C1 Formula for subtotal

    Hi Guys,
    I am writing a lengthy macro and am stuck in a part where I want to enter a subtotal formula in a cell. Since the whole macro would be creating many sheets and performing many actions on them, therefore, i want this formula to use R1C1 format for subtotal. But at the same time I want it to take a range which will start from a static cell e.g. U2 and go till the final row of U column.

    When recording the same it gave me the below script:

    ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,R[-416]C:R[-1]C)"

    This does not cater my problem as, the sheet would have different no. of rows every time, therefore I want the formula to take the range from cell U2 to final row of U column. I tried tweaking it as below but it wouldn't work

    ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,"U2:U" & Finalrow)"

    Any help is appreciated.
    Thanks... Murtaza
    Last edited by murtaza.khan; 06-12-2013 at 09:56 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    11-20-2012
    Location
    Seattle, WA USA
    MS-Off Ver
    Excel 2010
    Posts
    597

    Re: R1C1 Formula for subtotal

    try:

    Please Login or Register  to view this content.
    not sure if the syntax is correct, but since Finalrow is the last row used in the U column and you are subracting it from the activecell which is one more than the final row, it should give you the correct begining row

    given that Finalrow is derived correctly, and for each sheet that the formula will go in

    also, since you are starting from a static cell that is the same over sheets then you don't need to use R1C1. R1C1 is used if there are multiple columns and rows involved and the formula itself is in multiple places

    Please Login or Register  to view this content.
    should work too
    Last edited by scott.s.fower; 06-11-2013 at 08:33 PM.

  3. #3
    Registered User
    Join Date
    12-10-2012
    Location
    Canada
    MS-Off Ver
    Microsoft Excel: Mac 2011 & Microsoft Excel 2010
    Posts
    13

    Re: R1C1 Formula for subtotal

    Thanks Scott,
    Your script worked great. I don't know why my syntax was not working, but yes you are right theoretically it should.

    Anyway, I am so grateful for your response.

    I have another question, if you don't mind.

    I am try to select another cell after that script that you have suggested but it keeps giving me an error "Method 'Range' of Object '_Global failed". The next line that I am using is
    Range("R[3]C[-10]").Select

    I would highly appreciate if you can let me know if my syntax is correct or what is the issue.

    Thanks

+ 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