+ Reply to Thread
Results 1 to 7 of 7

VBA Code to look for specific text value and delete row

  1. #1
    Registered User
    Join Date
    10-18-2022
    Location
    London, England
    MS-Off Ver
    365
    Posts
    19

    VBA Code to look for specific text value and delete row

    Hello,

    I have an absence tracker containing a number of sheets and would like some VBA code to perform a certain task.

    - "current 6 months" sheet holds absence data in the current 6 month rolling period. I have a code which moves rows of data between sheets depending on absence start date.
    - "master data" sheet is regularly refreshed with system data to keep things in the report, like job titles etc up to date.

    I would like a piece of VBA code I can assign to a button on the ribbon which does the following:

    Current 6 months sheet

    Column B tells me whether the person is Active, inactive or terminated. This information is gained from a vlookup to the "master data" sheet.

    I would like a piece of code which I can assign to a button on the ribbon (so we have freedom of choice when the code is executed), which looks at column B and anywhere where it says "terminated", the code will delete the entire row, effectively removing all terminated people from the absence report.

    Kind Regards
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    08-03-2012
    Location
    Newcastle
    MS-Off Ver
    Excel 2007, 2010, 2013, 2016, Office 365
    Posts
    467

    Re: VBA Code to look for specific text value and delete row

    Hi Chris

    How about this code:
    Please Login or Register  to view this content.
    zeddy

  3. #3
    Valued Forum Contributor
    Join Date
    08-03-2012
    Location
    Newcastle
    MS-Off Ver
    Excel 2007, 2010, 2013, 2016, Office 365
    Posts
    467

    Re: VBA Code to look for specific text value and delete row

    Hi Chris

    The way I wrote that code was to apply your status-filter to whatever is currently filtered.
    So, for example, if you wanted to filter first by choosing say a Job Title or Location etc etc etc and then remove the Terminated status records you could do so.

    zeddy

  4. #4
    Valued Forum Contributor
    Join Date
    08-03-2012
    Location
    Newcastle
    MS-Off Ver
    Excel 2007, 2010, 2013, 2016, Office 365
    Posts
    467

    Re: VBA Code to look for specific text value and delete row

    Hi Chris

    I assume you could copy that code into a new module, and then assign it to a button on your Ribbon as you wanted.

    zeddy

  5. #5
    Registered User
    Join Date
    10-18-2022
    Location
    London, England
    MS-Off Ver
    365
    Posts
    19

    Re: VBA Code to look for specific text value and delete row

    Hi There

    Thanks very much for this. I have tested the code and it works

    I originally wanted the code to just clear all terminated employees, regardless of any filter applied. However, considering it, I actually like the idea of being able to filter on job title etc. I'll just have to tell the others to make sure all filters are cleared if they want to clear all terminated employees.

    One thing I have noticed is that it's temperamental when used on other sheets. For example, on the "previous 6 months" sheet, if there are no records, it will ask me to debug and then apply a filter showing from row 236. Is there any way to change it so it ONLY works on the "current 6 months" sheet? And throws an error message if someone tries to use it elsewhere?

    Chris
    Last edited by Chris_M_1987; 10-23-2022 at 12:03 PM. Reason: Changed

  6. #6
    Valued Forum Contributor
    Join Date
    08-03-2012
    Location
    Newcastle
    MS-Off Ver
    Excel 2007, 2010, 2013, 2016, Office 365
    Posts
    467

    Re: VBA Code to look for specific text value and delete row

    Hi Chris

    how about this then..
    Please Login or Register  to view this content.
    I could put some more error-checking in the code if you need it, but I was leaving a bit for you!

    zeddy

  7. #7
    Registered User
    Join Date
    10-18-2022
    Location
    London, England
    MS-Off Ver
    365
    Posts
    19

    Re: VBA Code to look for specific text value and delete row

    Hello,

    I'm currently learning VBA and have just finished learning what Object.Method (noun.verb) is and what parameters := (adverbs) and properties = (adjectives) are.

    So, as you might be able to tell, a complete beginner!

    Thanks very much for this!

    Kind Regards
    Chris

+ 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] Macro to Delete rows from specific text until other specific Text
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-11-2021, 10:35 AM
  2. Function to delete text from all cells that do not contain specific text values?
    By etwibell in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2018, 03:56 PM
  3. VBA code to delete specific data
    By grimston in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-06-2017, 01:06 PM
  4. Delete Rows with specific text in specific column
    By love2waltz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-12-2015, 10:16 AM
  5. VBA code to delete columns that contain a specific text in a range
    By rshnkmr39 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-11-2014, 01:48 PM
  6. Code to delete text left of a specific character
    By Yoshi64 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 10-21-2014, 05:38 AM
  7. VB Code to delete specific Columns of a specific worksheet
    By akh in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-22-2010, 09:14 AM

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