excel - 为工作簿中的多个工作表设置动态范围,不包括 2 个工作表。(错误 438)VBA
问题描述
我在执行此代码时收到错误消息 438。
我的工作簿中有 16 个工作表,我需要从中运行 14 个工作表的动态范围代码。
- 在每张纸中查找从单元格 A2 开始的范围(两张纸除外)。
- 并清除此选定范围的内容。*(我不想使用 .usedrange 函数)代码的目标是:
`子动态范围()
Dim ws4 As Worksheet
Dim twb As ThisWorkbook
Dim LastRow As Long
Dim LastColumn As Long
Dim StartCell As Range
Dim getLastCell As Range
Dim shtrng As Range
'Answer = MsgBox("The file may contain data, which will be lost if you proceed" & vbCrLf & "Save the
'file with a different file name to retain data" & vbCrLf & " Or Click Yes to proceed ", vbQuestion +
'vbYesNo + vbDefaultButton2, "Caution")
'If Answer = vbYes Then
Set twb = Application.ThisWorkbook
For Each ws4 In twb.Worksheets
Set ws4 = ActiveSheet
If ws4.Name <> "Generate Pending Log Report" And ws4.Name <> "PL1.Summary" Then
ws4.Select
LastRow = ws4.Cells.Find("*", ws4.Cells(1, 1), xlFormulas, xlPart, xlByRows, _
xlPrevious).Row
lastCol = ws4.Cells.Find("*", ws4.Cells(1, 1), xlFormulas, xlPart, xlByColumns, _
xlPrevious).Column
Set getLastCell = ws4.Cells(LastRow, lastCol)
Set shtrng = ActiveSheets.Range("A1", getLastCell(ws4)).Select
'I am getting an error 438
End If
Next ws4
'End If
结束子`
解决方案
改变这个:
Set shtrng = ActiveSheets.Range("A1", getLastCell(ws4)).Select
对此:
ActiveSheet.Range("A1", getLastCell).Select
推荐阅读
- mysql - 防止 MySQL 每个给定项目重复
- laravel - Laravel whereJsonContains 查询不起作用
- python - UserAttributeSimilarityValidator 应该如何在 Django REST Auth 中使用?
- c# - 有没有办法让参数以相同的形式传递给 form() 到 buttonEvent
- python - Python3:参数的条件扩展
- ios - 将数据从 TableViewController 传递到控制器单元格中的视图
- python-3.x - 为什么 ES6 (7/8...) 能够与 ES5(3) 兼容,因为语法差异如此之大?
- node.js - 在 MongoDB 上每秒保存多个文档返回超时
- python - BeautifulSoup 在谷歌 colab 中不起作用
- bash - 如何使用gnuplot制作两个值比较图?