+ Reply to Thread
Results 1 to 12 of 12

Macro to search for phrase and delete that cell and 1 cell to the right.

  1. #1
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Macro to search for phrase and delete that cell and 1 cell to the right.

    Need to search and find text, then delete that cell and the cell to its immediate right. Then move the cells up.

    Search would be anywhere on the worksheet. Not sure a sample will help much, but it is attached.

    TEST
    A 17
    B 1
    C 1
    D 1
    E 1
    TEST TOTAL 21
    This is what is in the workbook, I want to be able to search for TEST TOTAL, and it delete that and "21" and then move cells up.
    Attached Files Attached Files

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Macro to search for phrase and delete that cell and 1 cell to the right.

    try this:
    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Re: Macro to search for phrase and delete that cell and 1 cell to the right.

    Beautiful!

    If I have a dozen searches to perform do I just do?

    Please Login or Register  to view this content.

    also, how do you get it to repeat through the sheet? It isn't going through the entire worksheet. And oddly I have one instance of cells shifting to the left and that cell isn't even on the same row as a "Total".
    Last edited by taylorsm; 10-24-2017 at 06:27 PM.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,888

    Re: Macro to search for phrase and delete that cell and 1 cell to the right.

    You will need a separate If --Then statement for each item you wish to look up.

    Here is a link to understand Instr

    https://www.techonthenet.com/excel/formulas/instr.php

  5. #5
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Re: Macro to search for phrase and delete that cell and 1 cell to the right.

    Thanks. I think I can get the additional IFs. That really only leaves why it isn't looping through the entire sheet and why one cell is getting moved to the left randomly.

    I attached a sample. If you run your code you'll see what I mean. It doesn't remove all the Totals and M10 gets moved to the left one cell.
    Attached Files Attached Files

  6. #6
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Macro to search for phrase and delete that cell and 1 cell to the right.

    You might use this
    Please Login or Register  to view this content.
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  7. #7
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Re: Macro to search for phrase and delete that cell and 1 cell to the right.

    Thanks!

    Can we make it where if I have "X Total" "Z Total" "NO Total" that the search will apply to all cells with total in it?

    is that just the xlWhole to xlPart? I tested it and that looks right, but are there any unintended consequences?

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Macro to search for phrase and delete that cell and 1 cell to the right.

    As long as you don't have any cells containing "total" that you want to keep, it will be fine. Same applies to your other search terms of course. Remembering also that it's not just a complete word match, so "total" would match "totally" or "totalitarian" too.

  9. #9
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Re: Macro to search for phrase and delete that cell and 1 cell to the right.

    Ah, OK. I think that will work. Is there another option that would only do * Total, Total, or Total *, but not totally?

  10. #10
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: Macro to search for phrase and delete that cell and 1 cell to the right.

    Yes, you can actually use wildcards if you use xlWhole, so just include the other options in the itemArray
    Please Login or Register  to view this content.
    for example.

  11. #11
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Re: Macro to search for phrase and delete that cell and 1 cell to the right.

    Ah! Thanks!

  12. #12
    Forum Contributor
    Join Date
    01-09-2016
    Location
    USA,USA
    MS-Off Ver
    2016
    Posts
    1,192

    Re: Macro to search for phrase and delete that cell and 1 cell to the right.

    What do I need to look at to learn how to do something similar, like searching for text, then copying the cell next to it and then three down? So Like A1:B4?

+ 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. Macro for seaching a phrase and add 7 rows after that phrase
    By yhyhyhyh in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 11-10-2014, 11:52 PM
  2. Replies: 2
    Last Post: 10-09-2014, 05:14 AM
  3. Replies: 2
    Last Post: 01-15-2013, 02:55 AM
  4. Replies: 0
    Last Post: 09-26-2012, 02:02 PM
  5. Need a macro to search for a character in a cell, then delete all text prior to it.
    By lawyerdude666 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-28-2011, 10:36 AM
  6. search cell if blank delete cell shift values up
    By randell.graybill in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-22-2009, 10:01 PM
  7. Search a Range for a phrase and Format cell if found
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-26-2005, 06:05 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