Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Find a sheet within a workbook (If/Then/Else)

I have several sheets within a workbook. What I would like the program to do
is search through the sheet names and if there is a sheet name = to
txtName.Value then perform action, otherwise show a message telling the user
the input is not valid. I have already written the "then" and "else" portion
of this code, but I don't have the slightest idea how to have the program
search through the sheets to find the correct one (the "If"). Please help!



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Find a sheet within a workbook (If/Then/Else)

Maybe something like:

Sub getname()
Set txtName = Sheets("Sheet1").Range("A1")
v = txtName.Value
For Each sh In Sheets
If sh.Name = v Then
MsgBox ("FOUND IT!!")
Exit Sub
End If
Next
MsgBox ("did not find it.")
End Sub


--
Gary''s Student - gsnu200839


"Jacy Erdelt" wrote:

I have several sheets within a workbook. What I would like the program to do
is search through the sheet names and if there is a sheet name = to
txtName.Value then perform action, otherwise show a message telling the user
the input is not valid. I have already written the "then" and "else" portion
of this code, but I don't have the slightest idea how to have the program
search through the sheets to find the correct one (the "If"). Please help!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Find a sheet within a workbook (If/Then/Else)

You can do your test this way...

Dim TestName As String
....
On Error Resume Next
TestName = Sheets(txtName.Text).Name
If Err.Number = 0 Then
MsgBox "Exists"
Else
MsgBox "Doesn't exist"
End If

--
Rick (MVP - Excel)


"Jacy Erdelt" wrote in message
...
I have several sheets within a workbook. What I would like the program to
do
is search through the sheet names and if there is a sheet name = to
txtName.Value then perform action, otherwise show a message telling the
user
the input is not valid. I have already written the "then" and "else"
portion
of this code, but I don't have the slightest idea how to have the program
search through the sheets to find the correct one (the "If"). Please help!




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
how to find duplicate entry in one sheet and in workbook sanjay Excel Discussion (Misc queries) 1 May 30th 10 03:43 PM
Designating Sheet vs Workbook When Doing Find/Replace Paige Excel Programming 11 August 28th 08 11:45 PM
find workbook names that are in sheet RB Smissaert Excel Programming 9 April 23rd 08 06:59 PM
how can find sheet on workbook have so many sheet ? Huy Nguyen Excel Worksheet Functions 1 November 22nd 07 08:45 AM
find replace within sheet or workbook mcphc Excel Programming 5 April 23rd 07 03:28 PM


All times are GMT +1. The time now is 09:07 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"