+ Reply to Thread
Results 1 to 6 of 6

Thread: somewhat complex function needed

  1. #1
    Registered User
    Join Date
    10-10-2007
    Posts
    7

    Question somewhat complex function needed

    I need help figuring out how to do the following. I have 2 spreadsheets. Both have a column with unique numbers in them, let's call it TESTNUM. Both have a second column with a $ value in them I'll call PRICE. I want to create a macro or something that looks to see if TESTNUM from spreadsheet 2 is found in spreadsheet 1. If it is, AND if PRICE 2 is less than PRICE 1 then write PRICE 2 in the PRICE 1 field. Otherwise, don't change anything. I was trying to do it using a vlookup, but that doesn't seem to be robust enough to do some comparison of the fields before deciding which PRICE to use.

    Can someone help me? I need this by tomorrow. Thank you very much!!

  2. #2
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,636
    Maybe something like this?

    =IF(ISNUMBER(MATCH(A2,Sheet2!A:A,0)),IF(VLOOKUP(A2,Sheet2!A:B,2,0)<B2,VLOOKUP(A2,Sheet2!A:B,2,0),B2),B2)
    This formula would be placed in a new column on Sheet1.

    where A2 is your first TESTNUM and B2 contains PRICE1.

    Sheet2!A:A and Sheet2!B:B contains TESTNUMS for PRICE2
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  3. #3
    Registered User
    Join Date
    10-10-2007
    Posts
    7
    I'm having some problems getting it to pull the smaller value for some reason. I think we're close but I'll need to work on it some more and make sure I understand the logic of it more thoroughly. I'll let you know if I get it working or not. Thanks for your input.

  4. #4
    Registered User
    Join Date
    10-10-2007
    Posts
    7
    I'm still having problems. I have attached two sample spreadsheets, all_tests_07022008.xls and subset_tests_07022008.xls. I modified the formula you gave me to fit my spreadsheets. What I'm seeing happen is when it compares the value in column B (when it finds a match for the value of column A in both spreadsheets) no matter if the value in column B of all_tests_07022008.xls is smaller, it still puts in the value from column B of subset_tests_07022008.xls. Can anyone explain why? To me, it looks like this should work as I want it to, but it doesn't. Here's the formula I tried for row 11:

    =IF(ISNUMBER(MATCH(A11,[subset_tests_07022008.xls]Sheet1!$A:$A,0)), IF(VLOOKUP(A11,[subset_tests_07022008.xls]Sheet1!$A:$B,2,FALSE)<B11,VLOOKUP(A11,[subset_tests_07022008.xls]Sheet1!$A:$B,2,FALSE),B11),B11)

    I would really appreciate any help you could give me. Thank you very much!
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    10-10-2007
    Posts
    7
    I think I figured out my problem. The field type for column B in the all_tests_07022008.xls are not the correct type so apparently were not registering as smaller than the values in column B of subset_tests_07022008.xls. Once I created a new column with the values of column B multiplied by 1 it started working! Whoo hooo!

    Thanks for your help!

  6. #6
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,636
    Quote Originally Posted by BKolb
    I think I figured out my problem. The field type for column B in the all_tests_07022008.xls are not the correct type so apparently were not registering as smaller than the values in column B of subset_tests_07022008.xls. Once I created a new column with the values of column B multiplied by 1 it started working! Whoo hooo!

    Thanks for your help!
    I'm glad you figured it on your own... the best way to learn!

    Another couple of things you could've done without having to add new column...

    Type a 1 anywhere in the sheet and copy it..select the "bad" column and go to Edit|Paste Special and select Multiply... click Ok.

    or, select the "bad" column and go to Data|Text to Columns and simply click Finish.
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

+ 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.2.0