+ Reply to Thread
Results 1 to 14 of 14

Entering a formula into a cell using cells from a named range

  1. #1
    Registered User
    Join Date
    01-14-2013
    Location
    Maine
    MS-Off Ver
    Excel 2007
    Posts
    53

    Entering a formula into a cell using cells from a named range

    I have a range that I have named ZeroRepeats. The range is 5 rows and 7 columns. I need to enter a formula into a cell (that is not in the range) to calculate the average of the 5 values in the first column of the ZeroRepeats range. Mostly, my problem is that I don't really know how to reference cells within my named range.

    Thanks in advance!

  2. #2
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Entering a formula into a cell using cells from a named range

    try
    =AVERAGE(INDEX(zerorepeats,,1))
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  3. #3
    Registered User
    Join Date
    01-14-2013
    Location
    Maine
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Entering a formula into a cell using cells from a named range

    Here is how the suggested code looks after VBA Autoformats it:

    Range("C10") = Average(Index(ZeroRepeat, , 1))

    The code gives me a complie error "Sub or Function not defined", and highlights the word index. Any thoughts?

    The range is named currectly (I have already successfully used it here):
    Please Login or Register  to view this content.
    Last edited by arlu1201; 03-03-2013 at 02:36 PM.

  4. #4
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Entering a formula into a cell using cells from a named range

    Range("c10").FormulaR1C1 = "=average(INDEX(zerorepeats,,1))" works

  5. #5
    Registered User
    Join Date
    01-14-2013
    Location
    Maine
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Entering a formula into a cell using cells from a named range

    Oh yes I forgot the formula R1C1. Except now the cell containing the (C10) has a name error. the formula in the cell looks like this

    =AVERAGE(INDEX(ZeroRepeat, , 1))

    I am assuming because the worksheet does not know what ZeroRepeat is? Then range was named in VBA only. The other option is that I can select the 5 cells I need somehow using this reference:

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Entering a formula into a cell using cells from a named range

    Davidrias,

    Welcome to the forum.

    I have added code tags to your posts. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature below this post.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  7. #7
    Registered User
    Join Date
    01-14-2013
    Location
    Maine
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Entering a formula into a cell using cells from a named range

    I was trying to select the range I need like this

    Please Login or Register  to view this content.
    This is not working
    Last edited by davidrias; 03-03-2013 at 02:50 PM.

  8. #8
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,520

    Re: Entering a formula into a cell using cells from a named range

    Try this

    Please Login or Register  to view this content.
    or another way

    Please Login or Register  to view this content.
    Last edited by mike7952; 03-03-2013 at 05:23 PM.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Entering a formula into a cell using cells from a named range

    Perhaps something like this
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  10. #10
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Entering a formula into a cell using cells from a named range

    If ZeroRepeat is a VBA variable rather than a Named Range, how about this, changing the A1 to suit.

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  11. #11
    Registered User
    Join Date
    01-14-2013
    Location
    Maine
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Entering a formula into a cell using cells from a named range

    Yes, that works beautifully. Thank you.

    I declared ZeroRepeat as a Range but this code still seems to work.

  12. #12
    Registered User
    Join Date
    01-14-2013
    Location
    Maine
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Entering a formula into a cell using cells from a named range

    Yes, that works beautifully. Thank you.

    I declared ZeroRepeat as a Range but this code still seems to work.

  13. #13
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Entering a formula into a cell using cells from a named range

    You declared ZeroRepeat to be a Range variable in VBA.

  14. #14
    Registered User
    Join Date
    01-14-2013
    Location
    Maine
    MS-Off Ver
    Excel 2007
    Posts
    53

    Re: Entering a formula into a cell using cells from a named range

    I got ya. I am quite new to this as you could probably tell. Thank you for the help.

+ 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