+ Reply to Thread
Results 1 to 7 of 7

R1C1 issue

  1. #1
    Registered User
    Join Date
    08-13-2014
    Location
    Cumbria, uk
    MS-Off Ver
    2007
    Posts
    12

    R1C1 issue

    Hi

    Can anyone out there help me please!!

    I'm trying to enter this formula into a cell via VBA but the date of the 19/05/2015 needs to be a variable but can't get it to work. It needs to refer to today's date when you run the macro.

    ActiveCell.Offset(2, 0).Formula = "=AVERAGEIFS (Report1!H:H,Report1!G:G,""<>19/05/2015"",Report1!F:F,"">31/12/2013"",Report1!F:F,""<01/01/2015"")"

    I've converted some of the code to R1C1 to refer to a cell in the spreadsheet that has the date see below. I'm not sure how to translate H:H etc into R1C1. Any one help please? And if you know an easier way to use a variable please let me know.

    'ActiveCell.Offset(2, 0).Formula = "=AVERAGEIFS(Report1!H:H,Report1!G:G,>R[-2]C[0], Report1!F:F,"">31/12/2013"",Report1!F:F,""<01/01/2015"")"

    Thanks in advance.

    Mike

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: R1C1 issue

    In R1C1 notation, the columns are numbered across, just like the rows are numbered down. So A is C1, E is C5, F is C6, Z is C26 and so on. So Report1!C8 should be equivalent to Report1!H:H.

    You technically do not need the [0] in a relative reference, and Excel will likely remove it when the formula is entered. R[-2]C is the same as R[-2]C[0].

    It isn't directly related to your question, and I suppose there may be other considerations, but it seems that the 1st "if' criteria is superfluous. Any date between 31 Dec. 2013 and Jan 1 2015 will exclude any date in May 2015.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

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

    Re: R1C1 issue

    Can't you use the TODAY function in the formula?
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    08-13-2014
    Location
    Cumbria, uk
    MS-Off Ver
    2007
    Posts
    12

    Re: R1C1 issue

    Hi

    Appreciate the quick response. Simply when you know how. I'll give it a try tomorrow. The May 2015 date is in a different column. May date is in column G and the 2014 date is in column F.

    I did try the today() formula but for some reason it didn't work. I'll try it again tomorrow and see what the error message was. Maybe I didn't get the syntax correct.

    Thanks all for your help.

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

    Re: R1C1 issue

    I did try TODAY() with your original code but I got an error because of the space between AVERAGEIFS and the first bracket.

    In the code I posted I removed that space and it worked fine.

  6. #6
    Registered User
    Join Date
    08-13-2014
    Location
    Cumbria, uk
    MS-Off Ver
    2007
    Posts
    12

    Re: R1C1 issue

    Thanks for that. I'll try that as well tomorrow. A space!! How annoying.

  7. #7
    Registered User
    Join Date
    08-13-2014
    Location
    Cumbria, uk
    MS-Off Ver
    2007
    Posts
    12

    Re: R1C1 issue

    Hi

    So the Today() worked like a charm so thanks for the help. Naturally now that's done they now want to be able to choose a date. I've created a variable in VBA to store the date that's the easy bit. I've changed the VBA code below. Should that work though as the DateUsed variable shouldn't work in a formula in a cell? It appears to work but wanted to check. Also when I change it to = instead of <> it doesn't work at all. I've tried ""=&DateUsed"" and ""=""&DateUsed but doesn't work.

    Can I ask for your help again please?

    Thanks

    ActiveCell.Offset(21, 0).Formula = "=COUNTIFS(Report1!G:G,""<>&DateUsed"",Report1!F:F,"">31/12/2013"",Report1!F:F,""<01/01/2015"",Report1!H:H,"">=0"",Report1!H:H,""<=30"")" ' (4.1)

+ 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. Using R1C1 formula in VBA changes all references from CELL("address") function to R1C1?
    By dmasters4919 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-20-2014, 04:17 PM
  2. [SOLVED] R1C1 Syntax issue
    By jsuarez199 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-11-2013, 08:44 AM
  3. R1C1
    By Arne Hegefors in forum Excel General
    Replies: 1
    Last Post: 08-18-2006, 05:15 AM
  4. [SOLVED] A:1 now R1C1
    By Michael E W in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-24-2005, 07:40 PM
  5. R1C1 v A1
    By andy_hammer2001(remove) in forum Excel General
    Replies: 6
    Last Post: 10-13-2005, 12:05 AM

Tags for this Thread

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