简体   繁体   English

Excel:当其他单元格等于定义的值时,删除整行

[英]Excel: delete entire row when other cell equals a defined value

I have seen (searched) similar examples, but not quite what I am looking for. 我看过(搜索过)类似的例子,但不是我想要的。

I have a Workbook in Excel that has several sheets, Sheet A and B. These sheets have a bunch of data, so in order to display the most significant data on Sheet B from Sheet A, I want to mirror only the rows that I want to specify depending on the cell values on SheetA....I need to delete entire rows in Sheet B depending on the value in Sheet A. 我在Excel中有一个工作簿,其中有几个工作表,工作表A和工作表B。这些工作表有很多数据,因此,为了在工作表B中显示工作表A中最重要的数据,我只想镜像我想要的行根据SheetA上的单元格值进行指定。...我需要根据Sheet A中的值删除Sheet B中的整个行。

For instance, in Sheet AI have column X with 10 values (Yes/No), and I have linked the same data with formulas back to Sheet B. That is, that if in SheetA X1="Yes", then SheetB cell Y1="Done"...if SheetA X2="Yes", then SheetB cell Y2="Done"...if SheetA X3="No", then SheetB cell Y1="Missing"..and so on. 例如,在工作表AI中,列X具有10个值(是/否),并且我已将具有公式的相同数据链接回工作表B。也就是说,如果在工作表A X1 =“ Yes”中,则工作表B单元格Y1 = “完成” ...如果SheetA X2 =“是”,则SheetB单元格Y2 =“完成” ...如果SheetA X3 =“否”,则SheetB单元格Y1 =“缺少”。依此类推。

So I only want the rows in SheetB with cell values="Done" to be there and thus want rows with cell values="Missing" to be automatically deleted. 因此,我only希望SheetB中具有单元格值=“ Done”的行在那里,因此希望具有单元格值=“ Missing”的行被自动删除。 In this fashion, I would be creating a table that only includes the rows with "Done" values for the specified cell. 以这种方式,我将创建一个仅包含指定单元格具有“ Done”值的行的表。

I know there are macros in Excel, but I have never written code in VBA, and the language handlers and variables escapes me entirely. 我知道Excel中有宏,但是我从来没有用VBA编写过代码,语言处理程序和变量使我完全逃脱了。

Is there a way to write a macro that can be called with in a formula; 有没有一种方法可以编写可以在公式中调用的宏; that is, ex) if(A10="Yes", "", delete row macro here )??? 也就是说,例如)if(A10 =“ Yes”,“”, delete row macro here )???

Thanks! 谢谢!

From the wording in your question it seems you want to create a function that can be used in a cell that will alter other cells. 从问题中的措辞看来,您似乎想创建一个可以在将更改其他单元格的单元格中使用的函数。 That cannot be done. 那是不可能的。 The functions, when used in a formula, are limited to changing the cell itself, and not other cells. 这些函数在公式中使用时,仅限于更改单元格本身,而不是其他单元格。

More then one way to skin a cat. 还有一种为猫皮的方法。 Like Abe said you can`t use formula to alter other cells. 就像安倍说的那样,您不能使用公式来更改其他单元格。 But you can use VBA. 但是您可以使用VBA。 The below sub removes entire rows where the cell in range is equal to 1. But you can make it equal to whatever you want. 下面的子项将删除范围为1的整个行。但是您可以使其等于所需的任何行。

Sub DeleteRows()
Dim FoundCell As Range
Set FoundCell = Worksheets("SheetB").Range("YourRange").Find(what:=1)
Do Until FoundCell Is Nothing
    FoundCell.EntireRow.Delete
    Set FoundCell = Worksheets("SheetB").Range("YourRange").FindNext
Loop
End Sub

Of course this is extra work. 当然,这是额外的工作。 What you should do instead of copying the data from A to B and then processing it, just copy the done cells from A to B. 您应该做什么,而不是将数据从A复制到B然后进行处理,只需将完成的单元格从A复制到B。

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

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