excel - For循环每个工作簿
问题描述
我正在尝试遍历文件中的每个工作表,如果在工作簿中找到某个单词,请删除该单元格以及下面的其他 11 个单元格。
我放弃。我的代码不起作用。想不通为什么。
有人能帮助我吗?
Sub forEachWs()
Dim ws As Worksheet
Dim find As Range
For Each ws In ActiveWorkbook.Worksheets
Sheets(ws).Select
Set find = Cells.find(What:="nieusprawiedliwiona", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)
If Not find Is Nothing Then find.Activate
Range(Selection, Selection.Offset(11, 0)).Select
Selection.EntireRow.Delete
Next ws
End Sub
解决方案
好的。我让它工作了。
Sub forEachWs()
Dim ws As Worksheet
Dim find As Range
For Each ws In Worksheets
MsgBox (ws.Name)
ws.Select
Set find = Cells.find(What:="nieusprawiedliwiona", After:=ActiveCell, LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False)
If Not find Is Nothing Then find.Activate
Range(Selection, Selection.Offset(11, 0)).Select
Selection.EntireRow.Delete
Next ws
结束子
推荐阅读
- angular - 关于 Angular 组件装饰器行为的歧义在 Angular 文档中的描述
- python - 由于“numpy.core.multiarray 无法导入”而无法导入 shap 库
- laravel - 如何在页面上显示tinymce?
- xcode10 - 是否有覆盖功能以允许显示 pdf 的 webview 启用捏合和缩放?
- django - 如何允许来自特定国家的用户使用 django?
- python - 如何使用python选择多个文本坐标,使其不与同一背景图像中的多个图像坐标重叠?
- r - 如何使用 Pearson IV 型误差分布在 R 中运行回归?
- django - django docker 无法访问 nginx 端口
- python - 如何使用 SQLALCHEMY_BINDS 将 pandas.DataFrame.to_sql 与多个数据库一起使用
- opengl - GLSL中统一和常量之间的不同浮点行为