+ Reply to Thread
Results 1 to 13 of 13

Delete a cell and shift left if it contains the word "school"

  1. #1
    Registered User
    Join Date
    09-08-2016
    Location
    tampa, fl
    MS-Off Ver
    2011
    Posts
    6

    Delete a cell and shift left if it contains the word "school"

    Hello I would like VBA code that allows me to select all cells that contain the word "school" and delete the entire cell and shift to the left. Here is an example of what the info in one of theses cells would look like: VirtualSchoolCounselor(byDistrict)Fax: (407)377-8192

    So, I don't want to just delete the word school from the cell. I want the whole cell deleted based on the fact that it contains the word school. Thank you in advance!

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,026

    Re: Delete a cell and shift left if it contains the word "school"

    Are the cells containing "school" in a particular column or row or can they be anywhere on the sheet?
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    09-08-2016
    Location
    tampa, fl
    MS-Off Ver
    2011
    Posts
    6

    Re: Delete a cell and shift left if it contains the word "school"

    They can possibly appear in any column or any row

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,026

    Re: Delete a cell and shift left if it contains the word "school"

    This macro should work although how fast it will work depends on how large your data set is:
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-08-2016
    Location
    tampa, fl
    MS-Off Ver
    2011
    Posts
    6

    Re: Delete a cell and shift left if it contains the word "school"

    Thank you for taking the time to help me. That one didn't seem to work for me.
    Last edited by clundqui; 09-08-2016 at 02:00 PM.

  6. #6
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Delete a cell and shift left if it contains the word "school"

    I think Mumps1 forgot to add the direction. The default is xlup. In your case you need xlToLeft

    Please Login or Register  to view this content.

  7. #7
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Delete a cell and shift left if it contains the word "school"

    You may also try something like this provided no cell on the sheet has a formula error in it.

    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  8. #8
    Registered User
    Join Date
    09-08-2016
    Location
    tampa, fl
    MS-Off Ver
    2011
    Posts
    6

    Re: Delete a cell and shift left if it contains the word "school"

    Quote Originally Posted by sktneer View Post
    You may also try something like this provided no cell on the sheet has a formula error in it.

    Please Login or Register  to view this content.
    Thank you. This worked for me. I appreciate everyone that took the time to help!
    I also want to do this exact function for the phrase "n/a"
    Would I just repeat the code and replace school with n/a or is there a cleaner way I should do that?

  9. #9
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Delete a cell and shift left if it contains the word "school"

    If the cells contain #N/A returned by the formulas, the existing code will delete them and shift the cells to their left and if "n/a" is just a text string, the following code will do the job.

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    09-08-2016
    Location
    tampa, fl
    MS-Off Ver
    2011
    Posts
    6

    Re: Delete a cell and shift left if it contains the word "school"

    Quote Originally Posted by sktneer View Post
    If the cells contain #N/A returned by the formulas, the existing code will delete them and shift the cells to their left and if "n/a" is just a text string, the following code will do the job.

    Please Login or Register  to view this content.
    The "n/a" is I guess what you would consider string text. For example the cell might have this data in it: "Father Cell: n/a"
    The school code worked, but when I used the n/a code it replaced the old cell with this: "Father Cell: =NA()"

  11. #11
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Delete a cell and shift left if it contains the word "school"

    Replace "n/a" with "*n/a*" like below.....
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    09-08-2016
    Location
    tampa, fl
    MS-Off Ver
    2011
    Posts
    6

    Re: Delete a cell and shift left if it contains the word "school"

    Worked! Thank you!

  13. #13
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,655

    Re: Delete a cell and shift left if it contains the word "school"

    You're welcome. Glad to help.
    Thanks for the feedback.


    If that takes care of your original question, please mark your thread as Solved by selecting Thread Tools (just above your first post) --> Mark thread as solved.

+ 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] If cell equals "CR" then make cell to left negative and delete "CR".......
    By pasqualebaldi in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-14-2016, 07:51 PM
  2. Replies: 35
    Last Post: 01-13-2016, 02:16 AM
  3. Replies: 2
    Last Post: 01-27-2013, 12:20 AM
  4. [SOLVED] Macro to delete entire row if cell contains the word "total" or "Total"
    By theatricalveggie in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-10-2011, 12:38 PM
  5. Replies: 1
    Last Post: 10-31-2010, 02:56 AM
  6. Replies: 5
    Last Post: 06-26-2006, 09:23 PM
  7. [SOLVED] How 2 use right shift "<<" and left shift ">>" operator in excel?
    By v-2ajpau in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-28-2005, 09:40 AM

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