Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 07-06-2012, 07:23 AM
Colin Legg's Avatar
Colin Legg Colin Legg is offline Macro to conditionally create or go to worksheet Windows 7 32bit Macro to conditionally create or go to worksheet Office 2010 32bit
Expert
 
Join Date: Jan 2011
Location: UK
Posts: 369
Colin Legg will become famous soon enough
Default

Hi,

Here's one way:

Code:
Sub Main()
    
    Dim wstNew As Worksheet
    
    If WorksheetExists(WhichWorkbook:=ThisWorkbook, WorksheetName:="My New Worksheet") Then
        ThisWorkbook.Activate
        ThisWorkbook.Worksheets("My New Worksheet").Select
    Else
        With ThisWorkbook.Worksheets
            Set wstNew = .Add(After:=.Item(.Count))
            wstNew.Name = "My New Worksheet"
        End With
    End If
    
End Sub

Function WorksheetExists(ByVal WhichWorkbook As Workbook, ByRef WorksheetName As String) As Boolean
    On Error Resume Next
        
    WorksheetExists = Not WhichWorkbook.Worksheets(WorksheetName) Is Nothing
End Function
Reply With Quote
 

Tags
conditional, worksheet



Similar Threads
Thread Thread Starter Forum Replies Last Post
Create/delete New worksheet ibrahimaa Excel Programming 5 01-16-2012 11:53 PM
How to create a system folder with VB macro? Joe Patrick Word VBA 4 12-17-2011 02:04 PM
Create Custom menu using a macro twnty2 PowerPoint 0 06-29-2011 04:26 PM
How to create macro to paste text after style? Srivas Word 0 03-16-2010 05:28 AM
macro for comparing data from 3 columns and pasting into another worksheet ashukla Excel 1 06-24-2009 05:01 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:39 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft