Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Find Worksheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Find Worksheet

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Find Worksheet

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find tab in worksheet Rodney Excel Discussion (Misc queries) 3 March 9th 10 04:54 AM
how to find and unlink current worksheet from old worksheet kmjmail Excel Discussion (Misc queries) 3 January 12th 09 10:52 PM
Find Max Value in WorkSheet Corey Excel Worksheet Functions 11 January 14th 07 11:00 PM
Find the last used Row on a Worksheet poppy Excel Programming 4 November 25th 04 06:12 AM
Find a worksheet Luis Excel Programming 1 August 6th 04 11:45 AM


All times are GMT +1. The time now is 10:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"