View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Allllen Allllen is offline
external usenet poster
 
Posts: 341
Default Checking if Sheet Exists?

Sub sheetfinder()

Dim wsYourSheet As Worksheet
Dim sSheetName As String

sSheetName = InputBox("sheet name?")
If sSheetName = "" Then Exit Sub

On Error Resume Next
Set wsYourSheet = Worksheets(sSheetName)
On Error GoTo 0

If wsYourSheet Is Nothing Then
Set wsYourSheet = Worksheets.Add
wsYourSheet.Name = sSheetName
Else
Worksheets(sSheetName).Activate
End If

'it is now there and activated and you can put code in here to format it

End Sub

please rate me
--
Allllen


" wrote:

Hi,

Is there a way in Visual basic to check if a worksheet with a specific
name exists? If it does not exist, I want to add it and format it; if
it does, I just want to format it.

Thanks!

Brett