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.
Sub main()
Dim Filename As String
Filename = "NewSheet"
Call NewTab(Filename)
End Sub
Function MakeNewTab(Filename As String)
On Error Resume Next
Sheets(Filename).Select
If Err.Number <> 0 Then
Sheets.Add.Name = Filename
End If
End Function
Another example
is to use Error message to find the missing records.
Sub SearchRecord()
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
End Sub
No comments:
Post a Comment