Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Aug 2001
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Use VBA to check for the presence of a sheet (Excel 2000)

    I'd like to use VBA to check for the presence of a sheet. This will be a decision point in my code. If the sheet is not present it will need to be created, if it is present then I can move on to another step.
    My problem is that if the sheet doesn't exist - I get an error. And I don't think my error trapping skills are enough to handle both a true and false situation.

    Suggestions?

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Use VBA to check for the presence of a sheet (Excel 2000)

    Something like this should work:

    <pre>Dim oMySheet As Worksheet
    On Error Resume Next
    Set oMySheet = Worksheets("MySheet")
    On Error GoTo 0
    If oMySheet Is Nothing Then
    Set oMySheet = Worksheets.Add(After:=Worksheets(Worksheets.Count) )
    oMySheet.Name = "MySheet"
    End If
    </pre>

    Legare Coleman

  3. #3
    2 Star Lounger
    Join Date
    Aug 2001
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Use VBA to check for the presence of a sheet (Excel 2000)

    Works beautifully,
    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •