Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-14-2016, 03:50 PM
Offrddrver Offrddrver is offline Formula, Compare two cell's text and based on results output a number Windows 7 64bit Formula, Compare two cell's text and based on results output a number Office 2007
Novice
Formula, Compare two cell's text and based on results output a number
 
Join Date: Mar 2016
Location: Arizona
Posts: 2
Offrddrver is on a distinguished road
Default Formula, Compare two cell's text and based on results output a number

I have a very large, year long, data collection that has money, miles, companies, and categories in it. I need a formula that compares two cells in one row and outputs a value in that same row in another cell.



1. Column K is for category (Auto, Home, Dining, Medical, etc....) TEXT
2. Column D is for company names (100's of company names possible) TEXT
3. Column M will be for miles driven (total miles to the company site) NUMBER
4. The formula is only for one row at a time.

Criterial to formula:
1. if cell K is NOT = "Medical" then we don't care about cell D and cell M's output should be blank.

2. if cell K = "Medical" then also look in cell D and output # of miles driven in cell M based on the "text" within cell D.

3. Cell D will have multiple companies at 2 miles, and another set at 5 miles, and another set at 10 miles, and so on.

Here is what I have so far for Cell M2: (ROW 1 is for headers only)

=IF(K2="Medical",SUBSTITUTE(TRIM(IF(COUNT(SEARCH({ "A","B","C","D","E"},D2)),10,"") &IF(COUNT(SEARCH({"F","G","H","I"},D2)),5,"") &IF(COUNT(SEARCH({"J","K","L","M"},D2)),7,"")), " ",","))

As long as K2 = "Medical" I get the number in cell M2 that matches the company name from cell D2 (for this example I used the letters A-M to keep company names short)

However, the problem is that I get the word FALSE in cell M2 if K2 is NOT = "Medical". I need it to be blank so I can add column M later.

I hope that makes sense, any help is greatly appreciated.
Reply With Quote
  #2  
Old 03-14-2016, 09:49 PM
xor xor is offline Formula, Compare two cell's text and based on results output a number Windows 10 Formula, Compare two cell's text and based on results output a number Office 2016
Expert
 
Join Date: Oct 2015
Posts: 1,097
xor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to all
Default

You are almost there.

Try changing K2="Medical", SUBSTITUTE.... to
K2<>"Medical","",SUBSTITUTE....
and if you want the output as number then precede the first IF with --
Reply With Quote
  #3  
Old 03-15-2016, 09:08 PM
Offrddrver Offrddrver is offline Formula, Compare two cell's text and based on results output a number Windows 7 64bit Formula, Compare two cell's text and based on results output a number Office 2007
Novice
Formula, Compare two cell's text and based on results output a number
 
Join Date: Mar 2016
Location: Arizona
Posts: 2
Offrddrver is on a distinguished road
Default

Thank you for the reply.

I changed my original formula in two ways:

1. =IF(K2<>"Medical","",SUBSTITUTE(TRIM(IF(COUNT(SEAR CH({ "A","B","C","D","E"},D2)),10,"") &IF(COUNT(SEARCH({"F","G","H","I"},D2)),5,"") &IF(COUNT(SEARCH({"J","K","L","M"},D2)),7,"")), " ",","))
1a. This now gives blanks if column K if NOT = "Medical" - Good
1b. This now gives the proper number output in M, but the #'s 10, 5, or 7 are in TEXT form as they are shifted to the left side of the M column cells.
1c. This formula does NOT allow me to add up column M when finished with all entries; it gives a 0.00 result (End of column is just =SUM(M2:M2034))

So then added the following as you noted:

2. =--IF(K2="Medical","",SUBSTITUTE(TRIM(IF(COUNT(SEARCH ({ "A","B","C","D","E"},D2)),10,"") &IF(COUNT(SEARCH({"F","G","H","I"},D2)),5,"") &IF(COUNT(SEARCH({"J","K","L","M"},D2)),7,"")), " ",","))
2a. This outputs the proper NUMBER (10, 7, or 5) if "Medical" in column K - good
2b. This also gives a #VALUE output in Column M if column K is not "Medical" - Bad.
2c. Then as expected the Sum of column M = #VALUE


I then tried the following (added a zero between ""):

3. =--IF(K2="Medical","0",SUBSTITUTE(TRIM(IF(COUNT(SEARC H({ "A","B","C","D","E"},D2)),10,"") &IF(COUNT(SEARCH({"F","G","H","I"},D2)),5,"") &IF(COUNT(SEARCH({"J","K","L","M"},D2)),7,"")), " ",","))

3a. This gives a 0.00 valve for every M column cell that does not have "Medical" in Column K. **This is fine, it just doesn't look very clean.
3b. All column M results are correct (10, 7, or 5) if K="Medical" and if Column D has a value listed.
3c. However, if column K = Medical, and column D does not contain one of the values (A-M from the example) then I get a #VALUE. (IN TURN I get a total showing #Value)

Overall these are the closest results I have, and in case 3 it is not bad to get the #VALUE listed as it tells me that company is not in my A-M list within the formula, and that I need to add it.

Not ideal, not real clean looking, but it is working for now.

Let me know if you have any other ideas, and if not then that's okay also. I'll just keep plugging away at it over time.
Thanks for the help, you got me on a better path.
Reply With Quote
  #4  
Old 03-15-2016, 09:35 PM
xor xor is offline Formula, Compare two cell's text and based on results output a number Windows 10 Formula, Compare two cell's text and based on results output a number Office 2016
Expert
 
Join Date: Oct 2015
Posts: 1,097
xor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to all
Default

You are right.
Try to change the formula to:

=IF(K2<>"Medical","",
--SUBSTITUTE(TRIM(IF(COUNT(SEARCH({"A","B","C","D"," E"},D2)),10,"") &IF(COUNT(SEARCH({"F","G","H","I"},D2)),5,"") &IF(COUNT(SEARCH({"J","K","L","M"},D2)),7,"")),"", ","))
Reply With Quote
  #5  
Old 03-23-2016, 11:32 PM
xor xor is offline Formula, Compare two cell's text and based on results output a number Windows 10 Formula, Compare two cell's text and based on results output a number Office 2016
Expert
 
Join Date: Oct 2015
Posts: 1,097
xor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to allxor is a name known to all
Default

I had an idea as you asked for.
Have you any response?
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perform calc in active cell then highlight based on formula result grexcelman Excel Programming 4 01-12-2015 11:00 AM
How do I output text to a specific cell (x,y)? norwood Word VBA 2 01-31-2014 08:43 AM
Formula, Compare two cell's text and based on results output a number Formula in cell b1 using cell a1 if a1 is over certain number pumkinbug87 Excel 5 12-03-2013 12:34 PM
Change formula cell range based on cell value Scoth Excel 4 10-25-2012 07:51 AM
Formula, Compare two cell's text and based on results output a number Creating formula based on if data is correct in cell MattMurdock Excel 1 08-06-2012 03:11 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:08 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft