+ Reply to Thread
Results 1 to 20 of 20

Search rows to find specific text and move to a different column ?

  1. #1
    Registered User
    Join Date
    03-18-2014
    Location
    Miami, US
    MS-Off Ver
    Excel 2010
    Posts
    12

    Question Search rows to find specific text and move to a different column ?

    Hi all !

    I have a work sheet which has a lot of data. Unfortunately this data is all over the place (raw extract, only the rows are aligned).
    What I'm trying to accomplish is for excel to find cells which contain the partial text "PE" from all rows in columns J - AQ and move those texts to column I within the same rows.

    If I can't find a solution to this, then I'll be copying & pasting for a week (since it's not only that text I'll have to get in place).

    I don't know how to do macros, so if there's a formula for this, I'd have higher chances getting it to work.

    Any suggestion would be highly appreciated !

  2. #2
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Search rows to find specific text and move to a different column ?

    I'd recommend posting a small example of what you're working with. You can attach files by going to Go Advanced, and then scrolling down to Manage Attachments.

    Are you trying to dump all cells that have PE into a single cell of I?

    So if J2 = PE123 and M5 = PE999 should I5 = PE123PE999?

    If you're only looking for one match, it would be: =LOOKUP(1,1/SEARCH("PE",J2:AQ2),J2:AQ2) copied down
    Last edited by daffodil11; 03-18-2014 at 12:36 PM.
    Make Mom proud: Add to my reputation if I helped out!

    Make the Moderators happy: Mark the Thread as Solved if your question was answered!

  3. #3
    Registered User
    Join Date
    03-18-2014
    Location
    Miami, US
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Search rows to find specific text and move to a different column ?

    Thank you Daffodil !
    I can't add this file (or even part of it), as it is full of sensitive information (CC nbrs etc.).
    No, each cell containing "PE" should move to column I within the same row.

    Eg. J2=PE123 moves to I2 and displays PE123
    Z123 = Y45PE moves to I123 and displays Y45PE

  4. #4
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Search rows to find specific text and move to a different column ?

    But as I (poorly) pointed out in my example, will there be occasions when there's more than one PE per row?

    Try the formula I provided above and let me know if that works out.
    Last edited by daffodil11; 03-18-2014 at 12:52 PM.

  5. #5
    Registered User
    Join Date
    03-18-2014
    Location
    Miami, US
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Search rows to find specific text and move to a different column ?

    Thank you for bringing this up ! I hadn't even considered the possibility of multiple "PE"s within the same row yet. Yes, there may be up to 3 in very few instances.
    So I guess I'll have to create a few more empty columns to fit the data.
    Columns I,J,K should be the destination for all "PE" texts found and cut from columns L-AS.

  6. #6
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Search rows to find specific text and move to a different column ?

    Then likely a variation of the SMALL function. I will see if I can find it.

    Edit: Found it

    =IFERROR(INDEX($B$1:$E$1 (the range of the column headers)
    ,SMALL(IF(OFFSET($B$2:$E$2 (the range of columns which we're offsetting)
    ,MATCH($A10 (what we're looking for)
    ,$A$3:$A$6 (where we're looking for it)
    ,0),0)<>"",COLUMN($A$1:$D$1 (how many columns you're looking at, this means 1-4)
    -ROW(A$1)+1),COLUMN(A$1))),"") (the rest of this will remain the same)

    Let me try to translate this from my old project

  7. #7
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Search rows to find specific text and move to a different column ?

    I2:

    =IFERROR(INDEX($L2:$AQ2,SMALL(IF(ISNUMBER(SEARCH("PE",$L2:$AQ2)),COLUMN($A$2:$AH$2)-ROW(A$1)+1),COLUMN(A$1))),"")

    This is an Array formula, confirmed with Ctrl+Shift+Enter to exit the cell. This will put { } around the formula.

    Copy down and over.

    Fortunately, I leave myself a lot of notes and bookmarks for when I forget this stuff. https://www.excelforum.com/showthread.php?t=987015

  8. #8
    Registered User
    Join Date
    03-18-2014
    Location
    Miami, US
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Search rows to find specific text and move to a different column ?

    AWESOME !!! Much, much appreciated !
    Column I is now filled with all "PE" texts. But how do I get the additional fields to populate in J and K ?

  9. #9
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Search rows to find specific text and move to a different column ?

    Like I said, copy down and over. The formula is built to accommodate all three columns.

    The relative references near the end of the formula will adjust themselves as the formula is copied into K and L to:

    )-ROW(B$1)+1),COLUMN(B$1))),"")

    )-ROW(C$1)+1),COLUMN(C$1))),"")

  10. #10
    Registered User
    Join Date
    03-18-2014
    Location
    Miami, US
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Search rows to find specific text and move to a different column ?

    If I try to copy down and over to all 3 columns I am getting an error message: "You cannot change part of an array".

  11. #11
    Registered User
    Join Date
    03-18-2014
    Location
    Miami, US
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Search rows to find specific text and move to a different column ?

    Quote Originally Posted by Udaipur99 View Post
    If I try to copy down and over to all 3 columns I am getting an error message: "You cannot change part of an array".
    It works if I add the formula into I2,J2,K2 at the same time, but when dragging it down, it just adds the same data into all 3 cells of each row.

  12. #12
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Search rows to find specific text and move to a different column ?

    Copy the formula from your I2 exactly as you have it. I think you may have added some extra absolute references.

    I'd highly recommend putting together a small sample of your spreadsheet with 9-10 rows of your data, and I'll put the formula in a way that works.

  13. #13
    Registered User
    Join Date
    03-18-2014
    Location
    Miami, US
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Search rows to find specific text and move to a different column ?

    Ok, I changed and removed some stuff. Please see attached, and many thanks again !
    Last edited by FDibbins; 03-18-2014 at 08:27 PM. Reason: File removed at OP's request

  14. #14
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Search rows to find specific text and move to a different column ?

    It's good you attached a sample, because I wouldn't have never figured out it was all a simple math error. (I can't count apparently.)

    Also, make sure you only select 1 cell when you enter the array formula, or you will run into the error that pops up.

    So, I2:

    =IFERROR(INDEX($L8:$AQ8,SMALL(IF(ISNUMBER(SEARCH("PE",$L8:$AQ8)),COLUMN($A$2:$AF$2)-ROW(A$1)+1),COLUMN(A$1))),"")

    Then drag it over to K2

    Then drag I2:K2 down as far as needed


    The A2:AF2 part of the formula is the same as the range you're looking in, but dragged to the left. So if you were looking in D2:G2 (4 cells), the part of the formula that says A2:AF2 would becomes A2:D2 (still 4 cells). In the formula up there now, you are looking in L8:AQ8 (32 cells), so we need to make sure the COLUMN part is the first 32 cells A2:AF2.
    Last edited by daffodil11; 03-18-2014 at 04:29 PM.

  15. #15
    Registered User
    Join Date
    03-18-2014
    Location
    Miami, US
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Search rows to find specific text and move to a different column ?

    Perfect ! I just had to adjust the "8" to a "2", since it was pulling the "PE" from the wrong rows. So the formula which works for me is:

    =IFERROR(INDEX($L2:$AQ2,SMALL(IF(ISNUMBER(SEARCH("PE",$L2:$AQ2)),COLUMN($A$2:$AF$2)-ROW(A$1)+1),COLUMN(A$1))),"")

    Thank you so much for spending so much time on this !! It makes my job a lot easier, and I know I'll be using this a lot !

  16. #16
    Registered User
    Join Date
    03-18-2014
    Location
    Miami, US
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Search rows to find specific text and move to a different column ?

    Is there any way I can remove the xls file from this thread ?

  17. #17
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Search rows to find specific text and move to a different column ?

    Cool, glad it all worked out. It was my pleasure.

    Come back anytime.

  18. #18
    Registered User
    Join Date
    03-18-2014
    Location
    Miami, US
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Search rows to find specific text and move to a different column ?

    2 more questions came up:

    1) How can I adjust the formula to find cells starting with a specific number instead for finding cells with a certain part of a text ?
    So instead of searching for "PE":
    =IFERROR(INDEX($N2:$BR2,SMALL(IF(ISNUMBER(SEARCH("PE",$N2:$BR2)),COLUMN($A$2:$AF$2)-ROW(A$1)+1),COLUMN(A$1))),"")
    I want to find all cells starting with "9". I googled and tried this:
    =IFERROR(INDEX($N2:$BR2,SMALL(IF(ISNUMBER(SEARCH("9*",$N2:$BR2)),COLUMN($A$2:$AF$2)-ROW(A$1)+1),COLUMN(A$1))),"")
    but I am getting a response that the formula is incorrect.

    2) How do I close a thread once it's solved ?

  19. #19
    Forum Expert daffodil11's Avatar
    Join Date
    07-11-2013
    Location
    Phoenixville, PA
    MS-Off Ver
    MS Office 2016
    Posts
    4,465

    Re: Search rows to find specific text and move to a different column ?

    Remember, the Column() part has to match the number of Columns in the range you're choosing.

    N2:BR2 = 57 Columns

    Therefore, the Column() range has to include 57 columns, starting with A.


    =IFERROR(INDEX($N2:$BR2,SMALL(IF(ISNUMBER(SEARCH("9*",$N2:$BR2)),COLUMN($A$2:$BE$2)-ROW(A$1)+1),COLUMN(A$1))),"")

    because A2:BE2 = 57 COLUMNS

    I never saved a copy of your worksheet since you said it was sensitive information, but you might also want to try using LEFT instead of SEARCH:

    LEFT(range) pulls the first item in the string

    =IFERROR(INDEX($N2:$BR2,SMALL(IF(LEFT($N2:$BR2)="9",COLUMN($A$2:$BE$2)-ROW(A$1)+1),COLUMN(A$1))),"")
    Last edited by daffodil11; 03-19-2014 at 12:06 PM.

  20. #20
    Registered User
    Join Date
    03-18-2014
    Location
    Miami, US
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Search rows to find specific text and move to a different column ?

    Thank you again, Daffodil !

    Either of the above causes a "0" to be added as the resulting cell value.

+ 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. Replies: 4
    Last Post: 09-18-2012, 10:54 AM
  2. Move a specific text from on column and append to another
    By helloworld2012 in forum Excel General
    Replies: 1
    Last Post: 03-22-2011, 04:46 AM
  3. Search for any Text String in specific range and copy + offset + move
    By FN2010 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 05-05-2010, 07:04 PM
  4. find name; search column; if date found-return 3 data pts; move to next row
    By cdl in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-28-2008, 10:43 AM
  5. Search column and move text formula
    By tommy in forum Excel General
    Replies: 0
    Last Post: 02-08-2005, 03:06 PM

Tags for this Thread

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