VBA宏过滤单元,如何处理“未找到单元格”错误

您所在的位置:网站首页 电脑显示未找到单元格 VBA宏过滤单元,如何处理“未找到单元格”错误

VBA宏过滤单元,如何处理“未找到单元格”错误

2024-07-13 03:34| 来源: 网络整理| 查看: 265

我有将工作表上所有非空白单元格移动到其行中的第一个可用空白单元格的代码。

与对整个工作表运行的代码不同,我希望它忽略A&B列和第1、2和3行。

为此,我将.Range(.Cells(1, 1)更改为.Range(.Cells(4, 3),它在输入测试数据的新excel工作表上非常好地工作。这些测试数据只是随机分散的数据输入到不同的单元中。

当我在实际工作表上运行代码时,Set delrng = .Rows(rw).Cells.SpecialCells(xlCellTypeBlanks)会产生错误Run-time error '1004': No cells were found.,并无法执行任何操作。

谷歌正在讨论一些关于错误处理No Cells were found的话题,但我不认为仅仅删除这个错误对我有帮助。

谢谢。

代码语言:javascript复制Option Explicit Sub Shift_Left() Dim rw As Long, lr As Long, lc As Long, delrng As Range With Worksheets("Application Maturity Tracker") lr = .Cells.Find(what:="*", after:=.Cells(1, 1), LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, _ MatchCase:=False, SearchFormat:=False).Row lc = .Cells.Find(what:="*", after:=.Cells(1, 1), LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, _ MatchCase:=False, SearchFormat:=False).Column With .Range(.Cells(1, 1), .Cells(lr, lc)) For rw = 1 To .Rows.Count Set delrng = .Rows(rw).Cells.SpecialCells(xlCellTypeBlanks) If Not delrng Is Nothing Then delrng.Delete Shift:=xlToLeft End If Next rw End With End With End Sub


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3