Comments on: Help me figure out how to go about making Excel magic
http://ask.metafilter.com/110982/Help-me-figure-out-how-to-go-about-making-Excel-magic/
Comments on Ask MetaFilter post Help me figure out how to go about making Excel magicTue, 06 Jan 2009 21:35:00 -0800Tue, 06 Jan 2009 21:35:00 -0800en-ushttp://blogs.law.harvard.edu/tech/rss60Question: Help me figure out how to go about making Excel magic
http://ask.metafilter.com/110982/Help-me-figure-out-how-to-go-about-making-Excel-magic
How can I have Excel generate a new column with the data I need using certain conditions and pulling data from a pivot table? <br /><br /> I have thousands of items and 3 columns of values assigned to each item in a pivot table. I want to say "if column B and C values are identical then put that value in new cell" I also want to say "if values in B and C are not identical then pick whichever of the two is closest to the value of A and put that value in new cell"<br>
<br>
Any ideas on how I can do this? I'm relatively comfortable with excel and pivot tables but I've never written a macro before and don't know where to start.<br>
<br>
Thanks, all!post:ask.metafilter.com,2009:site.110982Tue, 06 Jan 2009 20:43:40 -0800ttynexcelpivotmacrodataanalysisresolvedBy: boeing82
http://ask.metafilter.com/110982/Help-me-figure-out-how-to-go-about-making-Excel-magic#1596759
I don't think you need a macro. You could just use an embedded Absolute Value function with an if/then statement (within another if/then statement). It's not necessarily pretty, but it works, and the logic is simple.<br>
<br>
See if this works for you:<br>
<br>
=IF(A1=B1,A1,(IF((IMABS((B1-A1))>(IMABS((C1-A1)))),C1,B1)))<br>
<br>
I'm assuming you know how to add the "$" so you can copy the formula down the column.comment:ask.metafilter.com,2009:site.110982-1596759Tue, 06 Jan 2009 21:35:00 -0800boeing82By: Pants!
http://ask.metafilter.com/110982/Help-me-figure-out-how-to-go-about-making-Excel-magic#1596782
I'm not sure if above will work because you want to compare B and C, not A and B, as far as I can tell. Try this:<br>
<br>
=IF(B1=C1,B1,MIN(ABS(C1-A1),ABS(B1-A1)))comment:ask.metafilter.com,2009:site.110982-1596782Tue, 06 Jan 2009 22:01:59 -0800Pants!By: ttyn
http://ask.metafilter.com/110982/Help-me-figure-out-how-to-go-about-making-Excel-magic#1597047
@Pants!<br>
<br>
The value if false results in the actual absolute value sum being placed in the cell rather the value of the existing number that is closest to A1.<br>
<br>
If A1 = 2, B1=2, C1=0, then I want the value of B1 to hold true for A1. Currently the formula generates a value of 0 because the difference of B1-A1 is 0.<br>
<br>
Also I forgot to add that if the absolute value of the difference between A1 and B1 is the same as A1 and C1, then it may as well keep the value of A1 without changing anything.comment:ask.metafilter.com,2009:site.110982-1597047Wed, 07 Jan 2009 06:52:39 -0800ttynBy: ttyn
http://ask.metafilter.com/110982/Help-me-figure-out-how-to-go-about-making-Excel-magic#1597129
Thanks to both of you setting me on the right path!<br>
<br>
If anyone is curious, I got it to work using this:<br>
<br>
=IF(B1<>C1,IF(ABS(B1-A1) < ABS(C1-A1),B1,C1),B1)</>comment:ask.metafilter.com,2009:site.110982-1597129Wed, 07 Jan 2009 08:10:56 -0800ttynBy: Pants!
http://ask.metafilter.com/110982/Help-me-figure-out-how-to-go-about-making-Excel-magic#1597176
Ahh, good point and good fix.comment:ask.metafilter.com,2009:site.110982-1597176Wed, 07 Jan 2009 08:43:12 -0800Pants!