Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Seems to be quite a simple one. But I can't figure it out.
Basically I've got a macro that saves a worksheet each month and renames it. All works fine, but as this is a shared workbook I want to put a failsafe in to make sure the macro to update isn't pressed twice thus trying to create a new sheet and save as the name. (because if this happens the macro crashes (because it can't rename the same). So I wasn to run a simple If function which searches a workbook for a name if it doesn't exist carry on with the code, if it does exist, then it will create a messagebox. Something like this but it needs to search the Sheet names not a range. sub searchmonth () Cmonth = ("M1") ' Inthis case February Set searchrange = workbooks ("export.xls") Set test = searchrange.find (what= Cmonth) If test Is Nothing Then ' it runs my code Else 'MsgBox End If End sub Thanks for any help! Carl |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
sub searchmonth ()
Cmonth = ("M1") ' Inthis case February Set export_wbk = workbooks ("export.xls") Found = false for each sht in export_wbk.sheets if sht.name = Cmonth then Found = True exit for end if next sht If Found = False Then ' it runs my code Else 'MsgBox End If End sub "Carlos" wrote: Seems to be quite a simple one. But I can't figure it out. Basically I've got a macro that saves a worksheet each month and renames it. All works fine, but as this is a shared workbook I want to put a failsafe in to make sure the macro to update isn't pressed twice thus trying to create a new sheet and save as the name. (because if this happens the macro crashes (because it can't rename the same). So I wasn to run a simple If function which searches a workbook for a name if it doesn't exist carry on with the code, if it does exist, then it will create a messagebox. Something like this but it needs to search the Sheet names not a range. sub searchmonth () Cmonth = ("M1") ' Inthis case February Set searchrange = workbooks ("export.xls") Set test = searchrange.find (what= Cmonth) If test Is Nothing Then ' it runs my code Else 'MsgBox End If End sub Thanks for any help! Carl |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Joel,
Many thanks again!! Works perfectly!! Cheers for your time Carl "Joel" wrote: sub searchmonth () Cmonth = ("M1") ' Inthis case February Set export_wbk = workbooks ("export.xls") Found = false for each sht in export_wbk.sheets if sht.name = Cmonth then Found = True exit for end if next sht If Found = False Then ' it runs my code Else 'MsgBox End If End sub "Carlos" wrote: Seems to be quite a simple one. But I can't figure it out. Basically I've got a macro that saves a worksheet each month and renames it. All works fine, but as this is a shared workbook I want to put a failsafe in to make sure the macro to update isn't pressed twice thus trying to create a new sheet and save as the name. (because if this happens the macro crashes (because it can't rename the same). So I wasn to run a simple If function which searches a workbook for a name if it doesn't exist carry on with the code, if it does exist, then it will create a messagebox. Something like this but it needs to search the Sheet names not a range. sub searchmonth () Cmonth = ("M1") ' Inthis case February Set searchrange = workbooks ("export.xls") Set test = searchrange.find (what= Cmonth) If test Is Nothing Then ' it runs my code Else 'MsgBox End If End sub Thanks for any help! Carl |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Find tab in worksheet | Excel Discussion (Misc queries) | |||
how to find and unlink current worksheet from old worksheet | Excel Discussion (Misc queries) | |||
Find Max Value in WorkSheet | Excel Worksheet Functions | |||
Find the last used Row on a Worksheet | Excel Programming | |||
Find a worksheet | Excel Programming |