+ Reply to Thread
Results 1 to 12 of 12

Conditional row addition

  1. #1
    Registered User
    Join Date
    06-16-2012
    Location
    london, england
    MS-Off Ver
    Excel 20101
    Posts
    11

    Conditional row addition

    Hello again,

    I have a programming problem with Excel.
    Let's say I have the following table which has four rows and six coloumns (Neglect the dots).

    .....A ..B ..C ...D ...E ...F
    1 ..35 .42 .48 .77 ........2
    2 ..50 .60 .56 .87 ........0
    3
    4

    I want to do the next: I want to check whether the number in cell F match number 2, Which in this case it does with row 1 only. Then if ok, I want to fill row number 3 with numbers in row 1 but with adding 2 to the first element less than 50 only.
    In this case after solution the table must look like:

    .....A ..B ..C ...D ...E ...F
    1 ..35 .42 .48 .77 ........2
    2 ..50 .60 .56 .87 ........0
    3 ..35 .42 .50 .77
    4 ..50 .60 .56 .87



    Is there any formula I can use ?

    Thanks in Advance

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

    Re: Conditional row addition

    I want to fill row number 3 with numbers in row 1 but with adding 2 to the first element less than 50 only.
    Do you mean the number which is less than 50 but the difference of 50 minus the number is the least?

    Also, why is row 2 duplicated in row 4 when there is 0 in column F of row 2?
    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]

  3. #3
    Registered User
    Join Date
    06-16-2012
    Location
    london, england
    MS-Off Ver
    Excel 20101
    Posts
    11

    Re: Conditional row addition

    Quote Originally Posted by arlu1201 View Post
    Do you mean the number which is less than 50 but the difference of 50 minus the number is the least?

    Also, why is row 2 duplicated in row 4 when there is 0 in column F of row 2?
    Yes , It must be less than the number in column F which in this case is = 2. That means the new row must be the same as the old one except adding 2 to the nearest number less than 50 (which is 48 in row 1).

    Row 2 duplicated beause the condition in column F is not satisfied ( the condition of row 2 must have number 2 in column F).

    I know it is a little bit complicated but I hope it is a good challenge for you.
    Thanks

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

    Re: Conditional row addition

    You mean 2 is added to C1 = 48 just because 50-2 gives 48?

    What if C1 was 47? Would it be ignored?

  5. #5
    Registered User
    Join Date
    06-16-2012
    Location
    london, england
    MS-Off Ver
    Excel 20101
    Posts
    11

    Re: Conditional row addition

    Quote Originally Posted by arlu1201 View Post
    You mean 2 is added to C1 = 48 just because 50-2 gives 48?

    What if C1 was 47? Would it be ignored?
    The code must check all the elements in row 1 and look what numbers less than 50 by 2. Then add 2 to the element to make it 50. So Yes.
    If C1 was 47 it must be ignored in that case.And leave the row beacause there is no number less than 50 by 2 only (just like row 2).
    Thanks

  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: Conditional row addition

    Do you have a sample file that you can upload?

  7. #7
    Registered User
    Join Date
    06-16-2012
    Location
    london, england
    MS-Off Ver
    Excel 20101
    Posts
    11

    Re: Conditional row addition

    I have attached xlsx file as an example.
    look at the golden cells. They only change because there is 2 in column F.

    Hope you help me with this.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    06-16-2012
    Location
    london, england
    MS-Off Ver
    Excel 20101
    Posts
    11

    Re: Conditional row addition

    @arlu1201

    I think you have not figure out a solution for my problem, have you ?

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

    Re: Conditional row addition

    i cannot see any logic in your result
    "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

  10. #10
    Registered User
    Join Date
    06-16-2012
    Location
    london, england
    MS-Off Ver
    Excel 20101
    Posts
    11

    Re: Conditional row addition

    @Martin
    I explained it. even I uploaded a file.
    Can you tell what is the unclear ?

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

    Re: Conditional row addition

    all of it!

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

    Re: Conditional row addition

    Why is 37 highlighted in the output given (column A) ?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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