+ Reply to Thread
Results 1 to 6 of 6

Need to delete rows that match values selected in combobox

  1. #1
    Registered User
    Join Date
    04-30-2015
    Location
    Newnan, GA
    MS-Off Ver
    2010
    Posts
    4

    Need to delete rows that match values selected in combobox

    This is my first post. I know next to nothing about VBA, other than what I have learned by trying and testing different bits of code. Currently I am creating a excel file that will track various tasks assigned to people in the office. I have created userforms to add and update tasks. I'm having trouble with the update form. I can pull in the information I need and update and change it, but what I want to do is to have a delete button that lets a user delete a task. Selection of the task is made by two comboboxes, the first is the client name and the second is the task. Depending on the selection, I need to then search a worksheet and find and delete the row that has both of the values the user selected. I can code it to delete based on one value (something I did in the spreadsheet that tracks the clients), but not two. I can imagine a scenario where the same task is assigned to different clients and using two values I think I can ensure that I'm deleting the right row. The code I have works sporadically, sometimes it will delete the row, but most of the time it won't. What am I doing wrong?

    This is the code I used for the two comoboboxes:

    Please Login or Register  to view this content.
    In case you're curious this is how I did it with one combobox:

    Please Login or Register  to view this content.
    Last edited by patojachula; 05-06-2015 at 04:28 PM.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Need to delete rows that match values selected in combobox

    This is getting close to how I would approach this.

    It looks like you are searching column B for one of the search strings, it isn't obvious if that is K1 or L1

    Having found a match,

    You should Select that row and use find or match to find the second search String.

    As you did not post your workbook I modified your code and tested it using a spreadsheet with text in K1 and L1

    I pasted k1 into several places in column B and L1 in an adjacent cell.


    Please Login or Register  to view this content.
    Last edited by mehmetcik; 05-06-2015 at 06:15 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Registered User
    Join Date
    04-30-2015
    Location
    Newnan, GA
    MS-Off Ver
    2010
    Posts
    4

    Re: Need to delete rows that match values selected in combobox

    Thank you so much! I totally didn't expect you to do the code for me. I'm sorry you had to write and test the code, but I didn't know how to load my Excel file. This is the link to the file in Google Drive https://drive.google.com/file/d/0B2O...ew?usp=sharing. The code probably looks a little Frankenstein-esque because I revised code from various sources to do what I need it to do. The add button is dependent on another workbook, but everything else should be fine. I fixed the runtime error I was getting with the code you provided and it works great on rows 1-7, but if I try to run it on row 8 and down, it just locks up. You don't have to code it for me, but could you please point me in the right direction as to what I need to do to keep it from locking up? Thanks so much!

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Need to delete rows that match values selected in combobox

    There is no data, and no instructions.

  5. #5
    Registered User
    Join Date
    04-30-2015
    Location
    Newnan, GA
    MS-Off Ver
    2010
    Posts
    4

    Re: Need to delete rows that match values selected in combobox

    I'm so sorry. Thanks for being patient with me. So basically there are two workbooks - Master Case List and Task Master. The Master Case List is basically a database of current cases and Task Master will be used to assign and track various client related assignments. The workbook I'm attaching (via hyperlink below) is the Task Master. Because not everyone in the office is tech savvy, to prevent unwanted changes to the actual data, the Current, Completed, and Datalist sheets contain the data and are hidden and the TaskMaster sheet contains various buttons that are assigned macors that allow a user to add to or modify the data on the other sheets or copy the relevant data to the TaskMaster sheet to allow a user to filter, sort, and print various task lists to their hearts' desire without endangering the underlying data. The Add button triggers a user form FormAddNewTask to add a new task. FormAddNewTask has a combobox that is populated using the current clients from the Master Case List, the data that is input on the FormAddNewTask populates the Current sheet in Task Master. For testing purposes, I have just added some generic data to the Current sheet. The Update button allows a user to modify an existing task. When FormUpdateTask is triggered it populates the two comboboxes based on the data in the Current sheet. After selecting the client and the task, the remaining fields are populated once the user hits enter. (I think I've figured out how to automate that, but I'll work on that code later.) What I am having problems with is the Delete button on the user form FormUpdateTask that is triggered by clicking the Update button. Once you click on the delete button, it searches for the values selected in the comboboxes and deletes the row that contains both values. The code you provided works like a charm on rows 2-7, but on rows 8 and down, it just freezes and it is expected that this list will grow quite large. Again, you've done so much if you could please just point me in the right direction to keep it from locking up, it would be much appreciated. I tried various searches, but couldn't find anything that helped. Thanks again!

    You can access the workbook Task Master here: https://drive.google.com/file/d/0B2O...ew?usp=sharing.

  6. #6
    Registered User
    Join Date
    04-30-2015
    Location
    Newnan, GA
    MS-Off Ver
    2010
    Posts
    4

    Re: Need to delete rows that match values selected in combobox

    I was able to modify the code I found here (http://www.rondebruin.nl/win/winfile...DeleteCode.txt) to get it to work:

    Please Login or Register  to view this content.
    Thanks for your input!

+ 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. Hide Selected Rows that does not contain Values from combobox
    By chubbyjenz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-19-2015, 09:10 AM
  2. Delete rows if values match in a block of cells
    By Premangshu in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-21-2012, 05:47 AM
  3. Delete Selected Data on A Range Using ComboBox
    By fakehealer in forum Excel General
    Replies: 1
    Last Post: 11-10-2012, 06:24 AM
  4. Replies: 2
    Last Post: 08-28-2011, 02:39 AM
  5. Delete rows based on comboBox and offset values
    By excelpete in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-14-2009, 03:12 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