如何根据条件删除 Excel 工作表中的行
我有一个 Excel 工作簿,位于 A 列的 worksheet1 中,如果该列的值 = ERR 我希望将其删除(整行),这怎么可能?
PS:请记住,我以前从未使用过 VBA 或宏,因此非常感谢详细的描述。
I have an excel workbook, in worksheet1 in Column A, IF the value of that column = ERR I want it to be deleted (the entire row), how is that possible?
PS: keep in mind that I have never used VBA or Macros before, so detailed description is much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
手动或使用 VBA 使用自动过滤器(如下所示)是删除行的非常有效的方法
下面的代码
可以通过更改
strSheets = 轻松适应其他工作表数组(1, 4)。即此代码当前在第一张和第四张纸上运行
Using an autofilter either manually or with VBA (as below) is a very efficient way to remove rows
The code below
Can be readily adpated to other sheets by changing
strSheets = Array(1, 4)
. ie this code currently runs on the first and fourth sheets请注意,您使用 activesheet 执行的任何操作都会影响当前激活的工作表
正如您所说,您是初学者,为什么不记录一个宏并检查一下,这是通过查看后台代码来自动化流程的最佳方法
只需找到工作表上的“宏”选项卡并单击“录制新宏”,然后选择任意一行并执行您想做的操作,例如删除整行,只需删除整行,然后返回“宏”选项卡并单击“停止录制”。
现在单击 alt+F11 ,这将带您进入 VBA 编辑器,您可以在 vba 项目资源管理器字段中找到一些工作表和模块,如果您没有找到它,请使用 VBA 编辑器的视图选项卡进行搜索,现在单击 module1 并查看录制的宏,您会发现类似的内容
我希望我对您有所帮助,如果您需要更多帮助,请告诉我,谢谢
Note any operations that you do using activesheet , will be affected on the currently activated sheet
As your saying your a begginner, why dont you record a macro and check out, Thats the greatest way to automate your process by seeing the background code
Just find the macros tab on the sheet and click record new macro , then select any one of the row and do what you wanted to do , say deleting the entire row, just delete the entire row and now go back to macros tab and click stop recording .
Now click alt+F11 , this would take you to the VBA editor there you find some worksheets and modules in the vba project explorer field , if you dont find it search it using the view tab of the VBA editor, Now click on module1 and see the recorded macro , you will find something like these
I hope i helped you a bit , and if you need any more help please let me know, Thanks
最快的方法:
第二快的方法(这个方法也有很多变化):
多张纸的自动过滤方法:
Fastest method:
Second fastest method (lots of variations to this one too):
Autofilter method for multiple sheets:
假设 A 列的单元格中始终有值并且数据位于第一个工作表中,那么类似这样的操作应该可以满足您的要求:
Assuming there are always values in the cells in column A and that the data is in the first sheet, then something like this should do what you want: