Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm trying to run a macro, but sometimes theres a worksheet in place and
sometimes there isn't. If its not there I need to add it, but if it there and I try to add it i get an error. Anyone know how to do an if statement around something like this. Thanks, |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sub nosheet()
isthere = False For Each w In Worksheets If w.Name = "Sheetxx" Then isthere = True End If Next If isthere Then MsgBox ("it's already there") Else MsgBox ("It's not there") End If End Sub -- Gary''s Student gsnu200711 "jb" wrote: I'm trying to run a macro, but sometimes theres a worksheet in place and sometimes there isn't. If its not there I need to add it, but if it there and I try to add it i get an error. Anyone know how to do an if statement around something like this. Thanks, |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I stole this from Chip Pearson:
Function WorksheetExists(SheetName As Variant, _ Optional WhichBook As Workbook) As Boolean 'from Chip Pearson Dim WB As Workbook Set WB = IIf(WhichBook Is Nothing, ThisWorkbook, WhichBook) On Error Resume Next WorksheetExists = CBool(Len(WB.Worksheets(SheetName).Name) 0) End Function 'and you can use it like: .... if worksheetexists("myname",activeworkbook) then jb wrote: I'm trying to run a macro, but sometimes theres a worksheet in place and sometimes there isn't. If its not there I need to add it, but if it there and I try to add it i get an error. Anyone know how to do an if statement around something like this. Thanks, -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Test for the existence of a worksheet? | Excel Programming | |||
Test for file existence | Excel Programming | |||
Existence, Search, Test | Excel Programming | |||
Test for existence of Name | Excel Programming | |||
how do i test for the existence of a range name | Excel Programming |