Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Search for worksheet name

I'm new to VBA, and so my question is probably trivial to most he

I'm trying to find a sheet in workbook that best-matches the name the
user enters and then activates that sheet.


here's what i have so far: i get a "out of range error" when
activating the desired sheet.

I realize the my instr function will only give me the first instance,
but my real problem is activating the desired sheet.

Thanks!

-Phil

// ****** code below ******

Sub FindSheet()
Dim sh As Worksheet 'sh is var of worksheet class
Dim name As String

name = InputBox(prompt:=" enter desired worksheet to find ")

For Each sh In ActiveWorkbook.Sheets

If InStr(UCase(sh.name), UCase(name)) 0 Then 'this is
instring function
Exit For
End If

Next sh

Sheets("name").Activate 'activeworkbook is READ ONLY
' make active sheet the sought one


End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Search for worksheet name

Sub FindSheet()
Dim sh As Worksheet
Dim sname As String

sname = InputBox(prompt:=" enter desired worksheet to find ")
if sname < "" then
For Each sh In ActiveWorkbook.Sheets

If InStr(1,sh.name,sname,vbTextCompare) 0 Then
sh.Activate
Exit Sub
End If

Next sh
Msgbox "Likely match to " & sName & " not found"
Else
Msgbox "No name entered"
end if
End Sub

--
Regards,
Tom Ogilvy

"Phil" wrote:

I'm new to VBA, and so my question is probably trivial to most he

I'm trying to find a sheet in workbook that best-matches the name the
user enters and then activates that sheet.


here's what i have so far: i get a "out of range error" when
activating the desired sheet.

I realize the my instr function will only give me the first instance,
but my real problem is activating the desired sheet.

Thanks!

-Phil

// ****** code below ******

Sub FindSheet()
Dim sh As Worksheet 'sh is var of worksheet class
Dim name As String

name = InputBox(prompt:=" enter desired worksheet to find ")

For Each sh In ActiveWorkbook.Sheets

If InStr(UCase(sh.name), UCase(name)) 0 Then 'this is
instring function
Exit For
End If

Next sh

Sheets("name").Activate 'activeworkbook is READ ONLY
' make active sheet the sought one


End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 791
Default Search for worksheet name

Why don't you create a list of the sheets you have in the workbook and place
them in a dropdow box object for the user to select whatever they want.
Setting the event on change to select the sheet chose by the user?

"Phil" wrote:

I'm new to VBA, and so my question is probably trivial to most he

I'm trying to find a sheet in workbook that best-matches the name the
user enters and then activates that sheet.


here's what i have so far: i get a "out of range error" when
activating the desired sheet.

I realize the my instr function will only give me the first instance,
but my real problem is activating the desired sheet.

Thanks!

-Phil

// ****** code below ******

Sub FindSheet()
Dim sh As Worksheet 'sh is var of worksheet class
Dim name As String

name = InputBox(prompt:=" enter desired worksheet to find ")

For Each sh In ActiveWorkbook.Sheets

If InStr(UCase(sh.name), UCase(name)) 0 Then 'this is
instring function
Exit For
End If

Next sh

Sheets("name").Activate 'activeworkbook is READ ONLY
' make active sheet the sought one


End Sub


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Search for worksheet name

I really appreciate the help(worked perfectly), Tom. I hope
eventually I can contribute meaningfully to this group.

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
Search one worksheet to pull data into another worksheet HyperMite Excel Worksheet Functions 6 March 4th 09 01:53 PM
Can I search for a worksheet by Tab Name? Jerry L Excel Discussion (Misc queries) 2 November 10th 08 02:14 PM
Search one worksheet for values in another worksheet? ClayShooters Excel Discussion (Misc queries) 1 July 4th 06 03:01 PM
Search for worksheet jarvis1979 Excel Programming 2 July 6th 05 05:31 PM
Create a search Field within a worksheet to search command buttons Ed P[_2_] Excel Programming 1 December 14th 04 08:04 PM


All times are GMT +1. The time now is 09:41 AM.

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

About Us

"It's about Microsoft Excel"