+ Reply to Thread
Results 1 to 12 of 12

formula >0

  1. #1
    Forum Contributor
    Join Date
    10-09-2006
    Posts
    212

    formula >0

    Awesome site, thanks.
    I have 4 columns of numbers. Column 1 minus column 2 = answer(col3). Then I add column 4 to col 3.
    Sometimes the answer between col1 and col2 is a negative number. This will throw off everything. Is it possible to have excel subtract col2 from col1 or vice versa which ever way will always give a positive?

    25 32 col1-col2=-7
    I hope it can be;
    25 32 col1-col2=7 without having to change the forumla around or the columns. sometimmes I have over 1500 cells in a column and the way i do it nopw is go through manually and change it when i get negative.

    Cheers, looking forwRD to help.
    Martin.

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565
    Hi there,

    You'll have use an IF statement that checks if the answer is less than zero and if it is either change the formula around or multiply the result by minus one i.e.,

    If (col1 - col2 < 0, col2 - col1, col1 - col2) or
    If (col1 - col2 < 0, (col1 - col2)*-1, col1 - col2)

    HTH

    Robert

  3. #3
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983
    in col c use

    =MAX(A1-B1,B1-A1)
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  4. #4
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    Or, simply use the ABS function, which will give you the absolute value of any number.

    =ABS(A1-B1)

    You don't have to change every formula, either. You can easily update all of your formulas in a few clicks:

    Change the first formula in column C (say, C1) then double-click on the fill handle in the lower right corner of that cell and it will automatically fill that formula down as many rows as are in the preceding column (as long as there are no blank rows). Rather than double-clicking, you could also click on the fill handle and drag down as many rows as you need.
    Last edited by Paul; 03-22-2007 at 09:39 PM.

  5. #5
    Forum Contributor
    Join Date
    10-09-2006
    Posts
    212
    Thanks you guys, I will try all of them. I do like the ABS formula though, but will both of them return a positive result? and I dont mean just changing the negative to a positive. It know to must subtract one from the other or change it around to get the right positive result. (col1-col2) or (col2-col1).

    Kindest Regards,
    Martin.

  6. #6
    Forum Contributor
    Join Date
    10-09-2006
    Posts
    212
    I got the ABS to work, sweet. Thanks much. If I have a row of numbers like the following:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    Is there a way I can get Exl to highlight the numbers in the row that could be ancored at say 3, then add 2. It would highlight 5, then add 2 highlight 7 add 2 highlight 9 etc.
    or if I start the sequence at 4 and add 6 it would highlight 10, then 16 then 22 then 28 then 34 etc.
    Is this possible?

    Kindest regards,
    Martin.

  7. #7
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by Martindelica
    I got the ABS to work, sweet. Thanks much. If I have a row of numbers like the following:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    Is there a way I can get Exl to highlight the numbers in the row that could be ancored at say 3, then add 2. It would highlight 5, then add 2 highlight 7 add 2 highlight 9 etc.
    or if I start the sequence at 4 and add 6 it would highlight 10, then 16 then 22 then 28 then 34 etc.
    Is this possible?

    Kindest regards,
    Martin.
    Hi,

    select the column, Format, Conditional Format,
    formula is
    =IF(MOD((A1-4)/6,1)=0,TRUE)
    set the Pattern required.

    hth
    ---
    Si fractum non sit, noli id reficere.

  8. #8
    Forum Contributor
    Join Date
    10-09-2006
    Posts
    212
    Hi Bryan thanks, as usual worked like a charm. If I have a col of the following numbers:
    23
    25
    26
    28
    29
    34
    32
    30
    29
    26
    23
    22
    The value goes up and down, is there a way to have excel list the numbers all going up? I dont mean sort. I mean result in the following;
    23,25,26,28,29,34,36,38,39,43,46,47.
    It would take the last number of the up slope and add the difference and so on. ie, 34-32=2, so it would be 34+2=36 then 32-30=2 add this to the 36=38...Exl would have to know when the number direction changes to go down and add the down numbers to the up going numbers to continue the sequence.

    Warmest regards,
    Martin.

  9. #9
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Hi,

    In A2 enter = A1

    Then in B2 enterthe below and drag down

    =B1+ABS(A2-A1)

    You will find the last 3 are different as you added 4 not 3

    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  10. #10
    Forum Contributor
    Join Date
    10-09-2006
    Posts
    212
    This still gives me the values going up and then they go back down. I need them to contiue the pattern but going up.
    23,24,25,26,27,28,27,26,25,24,23, Should the following
    23,24,25,26,27,28,29,30,31,32,33,
    or
    15,17,19,22,36,48,39,37,29,28, Should be the following;
    15,17,19,22,36,48,57,59,65,66,

    Kindest regards,
    Martin.

  11. #11
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887
    This still gives me the values going up and then they go back down. I need them to contiue the pattern but going up.
    23,24,25,26,27,28,27,26,25,24,23, Should the following
    23,24,25,26,27,28,29,30,31,32,33,
    or
    15,17,19,22,36,48,39,37,29,28, Should be the following;
    15,17,19,22,36,48,57,59,65,66,
    Martin, I just used VBANoob's formula and it worked perfectly. Are you sure you typed it correctly, or copy/pasted it in the right spot?

    If your column of #'s are in A1:A10, in B1 put the formula, =A1
    Then, in B2, put his formula, =B1+ABS(A2-A1)
    Fill that formula down to B10. It should give you the correct results.

    As Noob mentioned, the series you list in both of your last posts are not accurate.

    15, 17, 19, 22, 36, 48, 39, 37, 29, 28 should become
    15, 17, 19, 22, 36, 48, 57, 59, 67, 68 since there's a gap of 8 between 37 and 29, not a gap of 6

    23, 25, 26, 28, 29, 34, 32, 30, 29, 26, 23, 22 should become
    23, 25, 26, 28, 29, 34, 36, 38, 39, 42, 45, 46 since there's a gap of 3 between 29 and 26, not a gap of 4.

    Also check to see that automatic calculation is turned on in Tools-Options-Calculation.

  12. #12
    Forum Contributor
    Join Date
    10-09-2006
    Posts
    212

    Awesome

    This site truely is awesome!. Having stumbled across it on the net, I have shaved countless hours of my work due to those members that have provided me the right formulas. Thanks sooooo much guys.
    PS. Your absolutley right, the formula does work, I just typed in incorrectly. thanks again.

    Martin.

+ 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