简体   繁体   中英

Deleting a row on one worksheet based on a cell value in a different sheet

I'm very green when it comes to coding but have some basic knowledge (at least of the concepts). However, I'm unfamiliar with using VBA and the task I need seems to be a bit complex. I'm not even sure if it is entirely possible to accomplish.

Basically I have two worksheets, one with open "cases" and one with "closed" cases. Closed cases are marked with a value of "x" in a specific column (D). What I am looking to do is have a macro that will run through the closed worksheet and find rows with a "x" in column D. I would then like to select rows from the open worksheet based on the value in column A, which is a name and will match exactly. Then I want to delete those rows from the open sheet.

So the concept is I want a way to mark cases that are down and then clear the corresponding entry from the master list of open cases. Cases are split onto different worksheets but at the end I have a macro that lists them all on a master closed sheet. So find closed cases with a "x", match the name to the name on another sheet and delete that row.

Is this feasible, and if so, how can I go about it?

Thank you in advance for any help!

EDIT:

I've realized since I'm creating a master "closed" sheet already, I don't even need to search for the "x" value. All I need to do is match names from the closed sheet to the open sheet and delete them (them as in, the row they are contained in) from the open sheet.

Going to continue to look for answers as this should be simpler.

Yes, this does sound feasible. I would suggest trying to learn some basic VBA, breaking the problem up into small pieces of work and then trying to get all of these working before joining the whole process together.

So to start with you will need to find out how to loop through all of the values in a column and test them against a condition, you could use this thread as a starting point ( vba loop through column and if certain value then increment ) or Google it and see what you find for tutorials.

You will need to decide on how you want to store the data about the records that qualify (eg build an array or just write the data to another sheet temporarily). Whilst writing to another sheet may not be as efficient you have the benefit of being able to see the output very easily which can help with debugging, especially when you are just getting started.

You will then need to create a further procedure to open the other workbook, loop through the records and test to see if they are in your list and delete them if they are.

Have a go at each step and then ask the questions that you need to accompanied with your attempt at it.

One more tip that I found very useful when starting out with VBA. If you are not sure of the syntax to do something one way to find this out is to perform the equivalent actions manually whilst recording a macro. You can then look at the code behind the macro that Excel created automatically and sometimes all you need to do is replace the absolute cell references eg

range("A1").value

with relative references (eg relative to a parameter passed in or the active cell or a row represented by your current iteration through a loop etc.).

Hope this helps you get started.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM