+ Reply to Thread
Results 1 to 20 of 20

How to use IF to partially merge two strings

  1. #1
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    How to use IF to partially merge two strings

    Hi, my cells contain data like this: I-III 2010, and I'd like it to be Q1 2010,

    So here is my formula: IF(LEFT(C2,2)="IV", "Q2 "&RIGHT(C2, 4), "Q1 "&RIGHT(C2, 4)).

    It works well for Q1 and Q2. My question is: How to deal with VII-IX 2010 and X-XII 2010?

    I guess I need to use nested-IF's..
    Attached Files Attached Files
    Last edited by GIS2013; 09-08-2013 at 05:30 AM. Reason: A sample is added

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: How to use IF to partially merge two strings

    1) option
    Make a table of your data and use VLookup to get the value.

    After that you combine the values.

    2) option

    use CTRL + H for that (find and replace).

    If you have to do this job often, I would choose option 1.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: How to use IF to partially merge two strings

    @oeldere, take for example A1 (=2010) and B1(=I-III): what would VLOOKUP do? note I've got more years 2011-2013..

    *Again, a nested-if should solve it..

  4. #4
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How to use IF to partially merge two strings

    Hi,

    Just to confirm: are your desired results for VII-IX 2010 and X-XII 2010 Q3 2010 and Q4 2010 respectively?

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  5. #5
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: How to use IF to partially merge two strings

    Probably lik this (with VLookup).

    See the attached file.
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: How to use IF to partially merge two strings

    @Hello XOR. Yes, correct

  7. #7
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: How to use IF to partially merge two strings

    @oeldere, got you. thanks for the solution..

  8. #8
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: How to use IF to partially merge two strings

    Thanks for the reply.

    Glad I could help.

  9. #9
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: How to use IF to partially merge two strings

    @XOR - if your solution contains if's, I'd still want to see it, if that's ok

  10. #10
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How to use IF to partially merge two strings

    No, it wouldn't. A solution containing IF statements would be unfeasible since it would require as many clauses as there are potential variables, e.g.:

    =IF(LEFT(C1,FIND("-",C1)-1)="I","Return This",IF(LEFT(C1,FIND("-",C1)-1)="IV","Return This",IF(LEFT(C1,FIND("-",C1)-1)="VII","Return This",...

    , etc., etc.

    Which is precisely the sort of limitation which a simple table and a VLOOKUP, as given by oeldere, can overcome.

    If you want, and just for fun, this array formula will give you the results without a table, though I would hardly recommend such a solution!

    ="Q"&(2+MATCH(LEFT(C1,FIND("-",C1)-1),ROMAN(ROW($1:$1000)),0))/3&" 2010"

    Regards

  11. #11
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: How to use IF to partially merge two strings

    Many thanks XOR ... Very interesting, the feasibility limitation. I'll study later the ARRAY formula. For the while, I'm using the table+VLOOKUP option.

    *Maybe it'll help somebody: Note that after you (as thread opener) mark the thread as solved, you won't receive instant emails even if new posts are being added to it.

    Here is the reason for that: "There may also be other replies, but you will not receive any more notifications until you visit the forum again. All the best, Excel Help Forum"
    Last edited by GIS2013; 09-08-2013 at 07:13 AM.

  12. #12
    Forum Contributor
    Join Date
    07-02-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    197

    Re: How to use IF to partially merge two strings

    This is a solution without a VLOOKUP table:

    =LOOKUP(B1,{"I-III","IV-VI","VII-IX","X-XII"},{"Q1","Q2","Q3","Q4"})&" "&A1

  13. #13
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: How to use IF to partially merge two strings

    @Rambo - thanks. Could you explain how it works? LOOKUP searches for B1 in the vector result?
    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: How to use IF to partially merge two strings

    @Rambo - thanks. Could you explain how it works? LOOKUP searches for B1 in the vector result?
    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    07-02-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    197

    Re: How to use IF to partially merge two strings

    Quote Originally Posted by GIS2013 View Post
    @Rambo - thanks. Could you explain how it works? LOOKUP searches for B1 in the vector result?
    Please Login or Register  to view this content.
    Hi, it searches the value in B1 from the first lookup-vector. The match position in that vector will display the answer from the second answer-vector from the same position as in the first lookup-vector.

  16. #16
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: How to use IF to partially merge two strings

    Great. Obviously these two arrays must have identical size, right?

  17. #17
    Forum Contributor
    Join Date
    07-02-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    197

    Re: How to use IF to partially merge two strings

    Quote Originally Posted by GIS2013 View Post
    Great. Obviously these two arrays must have identical size, right?
    Yes, so it's not so useful if you have many lookup possibilites. Then it's better with a VLOOKUP table

  18. #18
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How to use IF to partially merge two strings

    "This is a solution without a VLOOKUP table:

    =LOOKUP(B1,{"I-III","IV-VI","VII-IX","X-XII"},{"Q1","Q2","Q3","Q4"})&" "&A1
    "

    Yes, but again, this has the same limitations as the potential IF() solution I mentioned - what would the result be for an entry containing "XIII-XV"? Or "XVI-XVIII"?

    Granted, if these are not possibilities (so that there are in fact only the four groups as originally given by the OP), then this is not an issue, but if they are then you would constantly be required to add elements to the array.

    Regards

  19. #19
    Forum Contributor
    Join Date
    12-30-2012
    Location
    Israel
    MS-Off Ver
    2007, 2016
    Posts
    642

    Re: How to use IF to partially merge two strings

    Yes, of course. Well it's all about these 4: i-iii, iv-vi, vii-ix, x-xii. So Without loss of generality..

  20. #20
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: How to use IF to partially merge two strings

    Ah, well if you're only concerned with those four then that's fine!

    Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Merge multiple cells in a column to strings no more than 100 characters long
    By exceler_52 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-23-2013, 01:49 PM
  2. [SOLVED] partially comparing strings vba
    By joetinger in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-19-2012, 08:54 PM
  3. Macro VBA - Merge Text Strings into One Cell with data validation
    By tldk in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-04-2011, 05:25 PM
  4. Is it possible to do search replace with partially underlined strings?
    By 321_contact in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-15-2010, 05:38 PM
  5. How can I merge two strings and use them as a name?
    By aron in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-31-2010, 06:08 PM

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