简体   繁体   English

根据不同工作表中的单元格值在一个工作表上删除一行

[英]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. 但是,我对使用VBA不熟悉,我需要完成的任务似乎有点复杂。 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). 已关闭的案例在特定列(D)中标记为“ x”。 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. 我想要做的是有一个宏,该宏将在关闭的工作表中运行,并在D列中查找带有“ x”的行。然后,我想根据A列中的值从打开的工作表中选择行。名称,并将完全匹配。 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. 因此,找到带有“ x”的闭合案例,将名称与另一张纸上的名称匹配,然后删除该行。

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. 我已经意识到,因为我已经在创建主“封闭”工作表,所以甚至不需要搜索“ x”值。 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. 我建议尝试学习一些基本的VBA,将问题分解为小部分工作,然后在将整个过程结合在一起之前尝试使所有这些工作正常进行。

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. 因此,从一开始,您将需要找出如何遍历列中的所有值并针对条件进行测试的方法,可以将该线程用作起点( vba遍历列,如果有特定值,则递增 )或谷歌它,看看你找到的教程。

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. 在开始使用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 然后,您可以查看Excel自动创建的宏后面的代码,有时您所需要做的就是替换绝对单元格引用,例如

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. 希望这可以帮助您入门。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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