One of the errors is the run time error which occurs when VBA cannot correctly execute a program statement. This is the error I sometimes use to fulfill my program goal.
For example, one of the typical run time errors is accessing a non-existent worksheet. I used this error message to help me determine whether the worksheet exists, otherwise build a new one.
Dim Filename As String
Filename = "NewSheet"
Function MakeNewTab(Filename As String)
On Error Resume Next
If Err.Number <> 0 Then
Sheets.Add.Name = Filename
Another example is to use Error message to find the missing records.
Dim Fingwhat As String
Dim Rng As Range
Dim FindResult As Range
Findwhat = 91 '''''' The record which is searched
Set Rng = Range("C8:C1000") ''''The searching Range
Set FindResult = Rng.Find(Findwhat, LookIn:=xlValues)
On Error Resume Next ''''The search result
c = FindResult.Address
If Err.Number <> 0 Then MsgBox "Can Not Find " & Findwhat
© Copyright Exceltipsandkeys All Rights Reserved.