Hi,
Can someone help me with writing a vba code for doing the following:
To start with I've made the following code for searching the particular worksheet, however I'm unable to make a code for the cancel button. Please help me with all that I've mentioned.
Can someone help me with writing a vba code for doing the following:
- Search a specific worksheet in the current workbook
- Copy that sheet in a new workbook (by creating a new workbook)
- Activate the new workbook
To start with I've made the following code for searching the particular worksheet, however I'm unable to make a code for the cancel button. Please help me with all that I've mentioned.
Code:
Function SheetExists(strWSName As String) As Boolean
Dim ws As Worksheet
On Error Resume Next
Set ws = Worksheets(strWSName)
If Not ws Is Nothing Then SheetExists = True
End Function
Sub Report()
Dim strWSName As String
SearchAgain:
strWSName = InputBox("Enter the Certificate #")
If strWSName = vbNullString Then
MsgBox "Type the certificate number"
Exit Sub
End If
If SheetExists(strWSName) Then
Worksheets(strWSName).Activate
Else
MsgBox "The sheet name does not exist!"
GoTo SearchAgain
End If
End Sub