+ Reply to Thread
Results 1 to 7 of 7

Nested If statements that dont stop reading when condition is met

  1. #1
    Registered User
    Join Date
    10-31-2008
    Location
    asia
    Posts
    32

    Nested If statements that dont stop reading when condition is met

    Firstly, I have to warn you this might take time.

    I have the following table on EXCEL:

    A B C
    1 UNIT_NAME Total_Capacity #_of_units
    2
    3 UNIT1 38,090 0
    4 UNIT2 48,012 1
    5 UNIT3 59,123 0
    6 UNIT4 71,027 0
    7 UNIT5 100,390 3

    To minimze the work on this user of this program, I promopt the user to fill in column C only, where he selects the number of air-conditioning units he wants. After the user enters these values, I call them on the next page where I created a receipt for the customer, and the receipt shows the units he purchashed.

    However the actual list of units that are avaliable are not only the 5 that I've listed, there are 18 units all together, so the table above is MUCH longer. The problem I am having is with the receipt, where I call the number of units the user purchased.

    I used nested if statements (which are limited to 7), below is an example of the code:

    =IF(C3>0,A3,IF(C4>0,A4,IF(C5>0,A5,IF(C6>0,A6,IF(C7>0,A7,IF(C8>0,A8,IF(C8>0,A8,IF(C9>0,A9.........etc........))))))))

    but the problem is (refer to table above) that when the if statement reads that C4 is positive, it take that number and stops reading for the next positive values.

    My Question:

    How can I create a code that stores the first positive value (probably in a variable) from the list (in the example above, C4) and continues to read and store for the next positive value (C7)....and continues to do so until the end of the 18-value (# of units) list?

    Thank you for your time!
    Last edited by VBA Noob; 10-31-2008 at 09:01 AM.

  2. #2
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326
    Hi and welcome to the board,
    please read forum rules and change your title accordingly
    Thx

  3. #3
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326
    Thx for changing your title

  4. #4
    Valued Forum Contributor ratcat's Avatar
    Join Date
    03-07-2008
    Location
    Rural NSW, Australia
    MS-Off Ver
    Vista 2007
    Posts
    1,111
    G'day

    There is an array formula you can use (see attachment).

    If the unit name aren't unique, you will have to apply the array formula across the 3 columns. By doing this you will increase the size of the workbook and slow down the calculation of the workbook especially if your computer not that A1.

    Please after editing the array formula confirm with Ctrl Shift Enter. The other columns has a Vlookup formula return the value of the Unit name.

    HTH
    Attached Files Attached Files
    Have I made you happy ??? If yes, please make me happy by pressing the http://www.excelforum.com/images/buttons/reputation-40b.png Add Reputation button in my post.
    Please don't forget to do the same to other contributors of this forum.

    Thanks
    I don't void confusion, I create it

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531
    maybe I'm missing the point but it sounds like you just want to sum the total number of units sold in one cell on your invoice ?

    if that's the case just use =SUM(Data!$C$3:$C$20)

    where Data is your Unit_Name / No. of Units sheet

  6. #6
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320
    i'd go for a pivot table!
    see example
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    07-24-2008
    Location
    Athome
    MS-Off Ver
    Excel 2013
    Posts
    127
    Can't a VLOOKUP work? you have a conditiional formula to display only the units you selected, then you use a vlookup baesd on those units.

+ 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