【发布时间】:2016-10-17 06:46:03
【问题描述】:
我在如何使用错误处理程序方面遇到了一些问题。请看下面的代码。基本上我想在迭代中找出每一行的空白单元格,如果找到,用黄色(44)为它们着色并在最后给出一个对话框(我添加一个整数,如果大于 1 它返回一个对话框)这是另一个问题我如何在错误处理过程中跳过这个?所以我使用 SpecialCells(xlCellTypeBlanks) 来查找空白单元格。因此,当没有空白单元格时,根据上述功能是错误的。我不确定我使用错误处理程序的正确程度。谁能在这里提供意见。
Sub checkblankcells()
Dim i, j, k, error, error1, error2, lastRow, LastCol As Long
Dim item, cntr As String
Dim r As Range
error2 = 0
lastRow = Range("D65000").End(xlUp).row
Application.ScreenUpdating = False
Sheets("Import").Activate
Dim counter As Long
For i = 1 To lastRow
With ActiveSheet
LastCol = .Cells(i, .Columns.Count).End(xlToLeft).Column
End With
Set r = Range(Cells(i, 4), Cells(i, LastCol))
On Error GoTo Check1
r.SpecialCells(xlCellTypeBlanks).Select
Selection.Interior.ColorIndex = 44
error2 = error2 + 1
Check1:
Resume Next
Next
'Deleting the Blank cell Check Numbers at the end of each row.
lastRow = Range("D65000").End(xlUp).row
Application.ScreenUpdating = False
Sheets("Import").Activate
For i = 1 To lastRow
With ActiveSheet
LastCol = .Cells(i, .Columns.Count).End(xlToLeft).Column
End With
Cells(i, LastCol).Select
Selection.Clear
Next
If error2 > 0 Then
MsgBox "Blank Activities in Yellow. Check Schedules", vbCritical, "TIL"
Exit Sub
End If
End Sub
【问题讨论】:
标签: excel error-handling vba