+ Reply to Thread
Results 1 to 3 of 3

if statements and counters

  1. #1
    Registered User
    Join Date
    07-09-2009
    Location
    Missouri
    MS-Off Ver
    Excel 2003
    Posts
    1

    if statements and counters

    It's been forever since I've programmed. in excel, how do you make a cell update without it being recursive as kind of a counter? Like, as a simplified example, I want to be able to enter a value in one cell, and if it is between 1 and 2 make cell a go up one but if it is between 2 and 3 make cell b go up one and if it is between 3 and 4 make cell c go up one and so on. i know to nest if statements to get it to decide which numbers it is between but how do i make it so the counter goes up where it is supposed to once the if statements determine which category it is in?
    Also, i want to know how to get an average of a range of cells but only the cells that have data in them, some of which may contain 0
    Last edited by DonkeyOte; 07-10-2009 at 04:02 AM.

  2. #2
    Registered User
    Join Date
    07-09-2009
    Location
    Cairo
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Need help with if statements and counters

    The formula should be entered in its cell and will not affact in another cell unless its linked to it.
    So if you entered a value in A1 , and want to change the value in C1 , enter a formula in C1 to monitor A1 and updates its value. So:
    if you enter 1 or 2 in Cell A1 ,to make cell A2 go up one: write in A2:
    =IF(OR(A1=1,A1=2),1,0) if A2 already has a value say 15 write =15+IF(OR(A1=1,A1=2),1,0)
    end etc. in all the cells you want to change.

    ـــــــــــــــــــــــــــــــــــــــــــــ
    Salah

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Need help with if statements and counters

    Welcome to the Board.

    Re: your first question...

    If you don't want to use VBA you would need in this instance to enable Iteration (Max Iteration set to 1) as your formulae would be circular, eg if we assume A2 contains the value of interest, ie for sake of demo:

    A1: =A1+(FLOOR(A2,1)=1)
    B1: =B1+(FLOOR(A2,1)=2)
    C1: =C1+(FLOOR(A2,1)=3)

    So as A2 alters so A1:C1 will update... it is imperative to note however that these Iterative calcs are Volatile so whenever XL recalculates they will iterate regardless of whether or not A2 was actually altered - meaning you could end up with these values increasing unexpectedly.

    For this reason a VBA Change Event is often best... ie use code to update A1:C1 as when A2 is altered... again a simple ex. for sake of demo:

    Please Login or Register  to view this content.
    Re: your 2nd question and Averages... let's assume you want to Average D1:D10 ignoring 0's (blanks you don't need to worry about as AVERAGE would ignore non-numerics), different approaches pending version of XL:

    XL2007:
    =AVERAGEIF(D1:D10,"<>0",D1:D10)

    Pre XL2007 - non Array assuming all values are +ve
    =SUM(D1:D10)/COUNTIF(D1:D10,">0")

    Pre XL2007 - Array form
    =AVERAGE(IF(D1:D10<>0,D1:D10))
    commited with CTRL + SHIFT + ENTER
    Last edited by DonkeyOte; 07-10-2009 at 04:02 AM.

+ 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