+ Reply to Thread
Results 1 to 8 of 8

count(R1C1:R[excelname]C1 worksheet not vba

  1. #1
    Forum Contributor
    Join Date
    02-13-2016
    Location
    CT USA
    MS-Off Ver
    office 365 subscription
    Posts
    178

    count(R1C1:R[excelname]C1 worksheet not vba

    As the title suggests, I want to use an excel name to define the integer value for the R argument.

    So far i have failed in getting the example function (count) to work with using names in the range designation.

    I suspect that i need to somehow designate that the datatype of the excel name is an integer, but i do not know how to do that in excel at the worksheet level. I did go to the cell for whose content the name points to
    and designated the value as a number with zero decimal places. but I suspect that excel keeps that number in floating point data type.

    I am seeking to do this because I want to avoid having to select the range end cell. I want to precalculate that range end cell once and then where ever i need to perform a function use that range end cell.

    It is tricky, in my case, as the range end cell is calculated by: DATEDIF(TEXT(R7C1, "dd-mmm-yyyy"), TODAY(), "d")...... This approach allows data to be missing within the data set including the most recent entry. the only requirements are that all my data starts at the first date (R7C1) and that there is a potential to record data for each day.

    please help me figure out a way to use variables or constants in an excel worksheet in conjunction with the r1c1 format.

    thank you
    bil

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

    Re: count(R1C1:R[excelname]C1 worksheet not vba

    Direct answer to your question -- use the INDIRECT() function: https://support.office.com/en-us/art...1-92b6306fa261 Note the optional 2nd [A1] argument that allows you to specify that the resulting reference text is an R1C1 reference and not an A1 reference. Some something like INDIRECT("R1C1:R"&excelname&"C1",FALSE) should work for you.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Contributor
    Join Date
    02-13-2016
    Location
    CT USA
    MS-Off Ver
    office 365 subscription
    Posts
    178

    Re: count(R1C1:R[excelname]C1 worksheet not vba

    this is exciting! i did go to the office reference you provided. they are clear but do not use INDIRECT in conjunction with any other function.

    What I remain confused about is that I am trying to alter the r1c1 reference in a function. in this case the function is count, but i have other functions as well. as far as I can see, INDIRECT knows nothing about functions. Am i supposed to do something like:

    count(INDIRECT("R1C1:R" &NumPotentialMeas& "C1", False) ??????

    Upon reflection on your answer I am impressed. It is very logical and I knew enough of the facts you used to have come up with it myself....but I was not that smart.

    thank you so much for sharing your experience. I will try your solution immediately.

    bil

    i will try it immediately.

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

    Re: count(R1C1:R[excelname]C1 worksheet not vba

    Am i supposed to do something like: count(INDIRECT("R1C1:R" &NumPotentialMeas& "C1", False)
    That (nesting one function within another function) would be one way to do it, yes. Note that you did not include the 2nd close parenthesis (making sure your open and close parentheses match up is a common source of frustration when nesting functions together), but the idea is correct.

  5. #5
    Forum Contributor
    Join Date
    02-13-2016
    Location
    CT USA
    MS-Off Ver
    office 365 subscription
    Posts
    178

    Re: count(R1C1:R[excelname]C1 worksheet not vba

    ok...tried it.


    here is what i tried in the spreadsheet:

    = COUNT(INDIRECT("R8C8:R"&NumPotentialMeas&"C8",FALSE))

    the forumula came up with an answer of 1 which is not correct as i am finally seeing that I have absolute r1c1 addressing going on. I need relative R[1]c[1] addressing.

    so i tried modifying your formula slightly:

    = COUNT(INDIRECT("R8C8:R["&NumPotentialMeas&"]C8",FALSE)) and got closer to the answer!!!!!!

    whwen i realized i needed a negative NumPotentialMeas it worked

    = COUNT(INDIRECT("R9C8:R["&-1*NumPotentialMeas&"]C8",FALSE))


    thank you for your help
    Last edited by whburling; 01-07-2018 at 01:22 PM. Reason: reduce exchanges

  6. #6
    Forum Contributor
    Join Date
    02-13-2016
    Location
    CT USA
    MS-Off Ver
    office 365 subscription
    Posts
    178

    Re: count(R1C1:R[excelname]C1 worksheet not vba

    the above formulat, = COUNT(INDIRECT("R9C8:R["&-1*NumPotentialMeas&"]C8",FALSE)) does work.

    But what I did not appreciate is that I can not drag the above across various columns and have the column number change to reflect the column the formula is in. Hence I tried to modify the above formula to the following:

    = COUNT(INDIRECT("R9C" &8&":" &"R["&-1*NumPotentialMeas&"]C"&8,FALSE))

    Thus R9C is fixed but I pulled out teh column number, 8, hoping the column number might increment. it did not do so. Is that because excel is not able to interpret the number 8 is a column number? how might I do that?

  7. #7
    Forum Contributor
    Join Date
    02-13-2016
    Location
    CT USA
    MS-Off Ver
    office 365 subscription
    Posts
    178

    Re: count(R1C1:R[excelname]C1 worksheet not vba

    the above formulat, = COUNT(INDIRECT("R9C8:R["&-1*NumPotentialMeas&"]C8",FALSE)) does work.

    But what I did not appreciate is that I can not drag the above across various columns and have the column number change to reflect the column the formula is in. Hence I tried to modify the above formula to the following:

    = COUNT(INDIRECT("R9C" &8&":" &"R["&-1*NumPotentialMeas&"]C"&8,FALSE))

    Thus R9C is fixed but I pulled out teh column number, 8, hoping the column number might increment. it did not do so. Is that because excel is not able to interpret the number 8 is a column number? how might I do that?

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

    Re: count(R1C1:R[excelname]C1 worksheet not vba

    I am not sure I understand what difficulty you are having. Is it a question of how to write relative references in R1C1 notation? If you are unfamiliar with R1C1 notation, review this under "using references in Excel formulas -> R1C1 reference style". I would have expected, rather than using the absolute ...C8..., that you would use a relative reference C[x] where x is the number of columns left (x<0) or right (x>0) of the column containing the formula.

+ 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. Defining a workbook, worksheet, with R1C1
    By TeloS53 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-08-2015, 06:09 AM
  2. 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
  3. total and subtotal and count from one worksheet to another worksheet
    By recain in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-02-2014, 03:07 PM
  4. [SOLVED] count occupied cells, but put count total in different worksheet
    By NewbieOfVBA in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-24-2012, 07:30 PM
  5. Replies: 2
    Last Post: 03-30-2010, 12:41 PM
  6. Reference to worksheet range in R1C1
    By JohanF in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-25-2006, 08:15 PM
  7. 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