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

I am trying to write vba code so a user can enter a worksheet name using an
inputbox. The worksheets are named by the client name. e.g. "Smith, Adam" and
I would like the user to be able to put in the name "Smith" and have the
correct worksheet selected, or a range of worksheets if there are more than 1
"Smith". How can I write this. The code I have written so far is:

Private Sub Workbook_Open()
On Error GoTo ErrorHandler
Dim stclname As String
Dim stermes As String

Enterclname:

stclname = InputBox("Enter the Client Name")
Worksheets(stclname).Activate

Exit_Workbook_Open:
Exit Sub

ErrorHandler:

stermes = MsgBox("Check the spelling")
Resume Enterclname


End Sub

Thanks in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 216
Default Like operator

Private Sub Workbook_Open()
On Error GoTo ErrorHandler
Dim stclname As String
Dim stermes As String
Dim sh As Worksheet

Enterclname:

stclname = InputBox("Enter the Client Name")
For Each sh In ThisWorkbook.Worksheets
If stclname Like "*" & sh.Name & "*" Then
sh.Activate
GoTo Exit_Workbook_Open
End If
Next sh

ErrorHandler:

stermes = MsgBox("Check the spelling")
Resume Enterclname

Exit_Workbook_Open:

End Sub

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"marianne" wrote in message
...
I am trying to write vba code so a user can enter a worksheet name using

an
inputbox. The worksheets are named by the client name. e.g. "Smith, Adam"

and
I would like the user to be able to put in the name "Smith" and have the
correct worksheet selected, or a range of worksheets if there are more

than 1
"Smith". How can I write this. The code I have written so far is:

Private Sub Workbook_Open()
On Error GoTo ErrorHandler
Dim stclname As String
Dim stermes As String

Enterclname:

stclname = InputBox("Enter the Client Name")
Worksheets(stclname).Activate

Exit_Workbook_Open:
Exit Sub

ErrorHandler:

stermes = MsgBox("Check the spelling")
Resume Enterclname


End Sub

Thanks in advance



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Like operator

Hello Marianne,

Please find my solution (see the code below). I modiffied a little bit
your code to open an appropriate array of sheet names.
Appropriate - means that the given pattern is searched in a set of
workbook names (function FindAllNames) .

Option Explicit

Private Sub Workbook_Open()
On Error GoTo ErrorHandler
Dim stClName As String
Dim stermes As String
Dim namesArr()


EnterClName:

stClName = InputBox("Enter the Client Name") 'it's the pattern
namesArr = FindAllNames(stClName)
Worksheets(namesArr).Select
Worksheets(namesArr(0)).Activate
Exit_Workbook_Open:
Exit Sub

ErrorHandler:

stermes = MsgBox("The pattern wasn't found. Check the spelling")
Resume EnterClName

End Sub

'search for the given pattern
Private Function FindAllNames(stClName As String)
Dim sheetNo As Integer
Dim RegEx
Dim iAllNames As Integer
Dim AllNames()
iAllNames = 0

Set RegEx = CreateObject("VBScript.RegExp")
RegEx.IgnoreCase = True
RegEx.Pattern = stClName

For sheetNo = 1 To Worksheets.Count
If RegEx.test(Worksheets(sheetNo).Name) Then
ReDim Preserve AllNames(iAllNames)
AllNames(iAllNames) = Worksheets(sheetNo).Name
iAllNames = iAllNames + 1
End If
Next

If iAllNames < 0 Then
FindAllNames = AllNames
End If
End Function

Best Regards,

Agnieszka

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 718
Default Like operator

I have home-made XLA that should help: http://cjoint.com/?fwqZQdNgus
It is not protected: you can view & edit the code and the userform

To have tabs alpha ordered, right click on arrows left of tabs list, and
select "Sort tabs"

To select a sheet:
Right-click on a cell and select "Select sheet"
You can type the beginning of the name: it will select corresponding entry
of the list.
To validate: press Enter or double-click on a name
To cancel: press Escape

HTH
--
AP

"marianne" a écrit dans le message de
news: ...
I am trying to write vba code so a user can enter a worksheet name using an
inputbox. The worksheets are named by the client name. e.g. "Smith, Adam"
and
I would like the user to be able to put in the name "Smith" and have the
correct worksheet selected, or a range of worksheets if there are more
than 1
"Smith". How can I write this. The code I have written so far is:

Private Sub Workbook_Open()
On Error GoTo ErrorHandler
Dim stclname As String
Dim stermes As String

Enterclname:

stclname = InputBox("Enter the Client Name")
Worksheets(stclname).Activate

Exit_Workbook_Open:
Exit Sub

ErrorHandler:

stermes = MsgBox("Check the spelling")
Resume Enterclname


End Sub

Thanks in advance



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Like operator

Thank you for the prompt response
I tried the code but I get an error
Compile error
Sub or Function not defined:
and it highlights "FindAllNames"


" wrote:

Hello Marianne,

Please find my solution (see the code below). I modiffied a little bit
your code to open an appropriate array of sheet names.
Appropriate - means that the given pattern is searched in a set of
workbook names (function FindAllNames) .

Option Explicit

Private Sub Workbook_Open()
On Error GoTo ErrorHandler
Dim stClName As String
Dim stermes As String
Dim namesArr()


EnterClName:

stClName = InputBox("Enter the Client Name") 'it's the pattern
namesArr = FindAllNames(stClName)
Worksheets(namesArr).Select
Worksheets(namesArr(0)).Activate
Exit_Workbook_Open:
Exit Sub

ErrorHandler:

stermes = MsgBox("The pattern wasn't found. Check the spelling")
Resume EnterClName

End Sub

'search for the given pattern
Private Function FindAllNames(stClName As String)
Dim sheetNo As Integer
Dim RegEx
Dim iAllNames As Integer
Dim AllNames()
iAllNames = 0

Set RegEx = CreateObject("VBScript.RegExp")
RegEx.IgnoreCase = True
RegEx.Pattern = stClName

For sheetNo = 1 To Worksheets.Count
If RegEx.test(Worksheets(sheetNo).Name) Then
ReDim Preserve AllNames(iAllNames)
AllNames(iAllNames) = Worksheets(sheetNo).Name
iAllNames = iAllNames + 1
End If
Next

If iAllNames < 0 Then
FindAllNames = AllNames
End If
End Function

Best Regards,

Agnieszka




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Like operator

Thank you for your prompt reply

I have tried your code but it doens't seem to work.
I get the error message twice and then the Inputbox comes up again.

Marianne


"Bob Phillips" wrote:

Private Sub Workbook_Open()
On Error GoTo ErrorHandler
Dim stclname As String
Dim stermes As String
Dim sh As Worksheet

Enterclname:

stclname = InputBox("Enter the Client Name")
For Each sh In ThisWorkbook.Worksheets
If stclname Like "*" & sh.Name & "*" Then
sh.Activate
GoTo Exit_Workbook_Open
End If
Next sh

ErrorHandler:

stermes = MsgBox("Check the spelling")
Resume Enterclname

Exit_Workbook_Open:

End Sub

--
HTH

Bob Phillips

(remove xxx from email address if mailing direct)

"marianne" wrote in message
...
I am trying to write vba code so a user can enter a worksheet name using

an
inputbox. The worksheets are named by the client name. e.g. "Smith, Adam"

and
I would like the user to be able to put in the name "Smith" and have the
correct worksheet selected, or a range of worksheets if there are more

than 1
"Smith". How can I write this. The code I have written so far is:

Private Sub Workbook_Open()
On Error GoTo ErrorHandler
Dim stclname As String
Dim stermes As String

Enterclname:

stclname = InputBox("Enter the Client Name")
Worksheets(stclname).Activate

Exit_Workbook_Open:
Exit Sub

ErrorHandler:

stermes = MsgBox("Check the spelling")
Resume Enterclname


End Sub

Thanks in advance




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Like operator

Hi Marianne,

You should try to use whole code (not only the first procedure).
Here you have the part defining the FindAllNames function (which was
also given before).

'search for the given pattern
Private Function FindAllNames(stClName As String)
Dim sheetNo As Integer
Dim RegEx
Dim iAllNames As Integer
Dim AllNames()
iAllNames = 0

Set RegEx = CreateObject("VBScript.RegExp")
RegEx.IgnoreCase = True
RegEx.Pattern = stClName

For sheetNo = 1 To Worksheets.Count
If RegEx.test(Worksheets(sheetNo).Name) Then
ReDim Preserve AllNames(iAllNames)
AllNames(iAllNames) = Worksheets(sheetNo).Name
iAllNames = iAllNames + 1
End If
Next

If iAllNames < 0 Then
FindAllNames = AllNames
End If
End Function


Good luck,

Aga

marianne napisal(a):
Thank you for the prompt response
I tried the code but I get an error
Compile error
Sub or Function not defined:
and it highlights "FindAllNames"


" wrote:

Hello Marianne,

Please find my solution (see the code below). I modiffied a little bit
your code to open an appropriate array of sheet names.
Appropriate - means that the given pattern is searched in a set of
workbook names (function FindAllNames) .

Option Explicit

Private Sub Workbook_Open()
On Error GoTo ErrorHandler
Dim stClName As String
Dim stermes As String
Dim namesArr()


EnterClName:

stClName = InputBox("Enter the Client Name") 'it's the pattern
namesArr = FindAllNames(stClName)
Worksheets(namesArr).Select
Worksheets(namesArr(0)).Activate
Exit_Workbook_Open:
Exit Sub

ErrorHandler:

stermes = MsgBox("The pattern wasn't found. Check the spelling")
Resume EnterClName

End Sub

Best Regards,

Agnieszka



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
Operator for Contains Leanne M (Aussie) Excel Worksheet Functions 2 October 21st 08 11:01 AM
Operator kittycris Excel Worksheet Functions 3 January 11th 07 01:36 AM
IN operator Suzanne Excel Worksheet Functions 4 May 10th 06 06:28 PM
Mod operator R Avery Excel Programming 7 September 2nd 04 03:03 AM
Can the AND operator be of use here? Milind Excel Programming 3 July 27th 03 11:17 PM


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