Results 1 to 3 of 3

Thread: [RESOLVED] Find specific data in sheet name

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Location
    Montreal, Canada
    Posts
    152

    Resolved [RESOLVED] Find specific data in sheet name

    Hi guys,

    now I need to find specific data in sheet name
    all sheets name in the workbook are on the same pattern.
    Here is the patern: "XXX YYY ZZZ"

    All X, Y and Z are variable in lenght and they are seperate with a space.

    I need the value of Z but how to find it with a variable lenght????

    Thanks

    Here is my code with where I need to introduce de tricky "last part of the sheet name"




    VB Code:
    1. With Workbooks(lcFileName)
    2.             For lnSheetId = 2 To .Sheets.Count
    3.             ' sheet 1 is Dept... now starting from sheet 2 check if it is Ss-Dept
    4.                 If Not IsNumeric(.Sheets(lnSheetId).Name) And Len(Trim(.Sheets(lnSheetId).Name)) > 3 Then
    5.                     SsDept = .Sheets(lnSheetId).Name
    6.  
    7.                     'Need to find the specific data HERE
    8.                     'Need to find the specific data HERE
    9.  
    10.  
    11.                     SsDeptIndex = Workbooks(fullname).Sheets(tsNameFile & " " & SsDeptName).Index - 1 'marche pas
    12.                    
    13.                     'if sheet already exists in the Department Workbook
    14.                     If SheetExists(fullname, SsDept) = True Then
    15.                         Workbooks(fullname).Sheets(SsDept).Delete
    16.                     End If
    17.                     .Sheets(SsDept).Copy After:=Workbooks(fullname).Sheets(SsDeptIndex)
    18.                 End If
    19.             Next lnSheetId
    20.         End With

  2. #2
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Find specific data in sheet name

    If the name always has 3 parts separated by a single space between the parts, the following should work:

    VB Code:
    1. Dim Array1() As String
    2.     Dim shName As String
    3.     shName = "XXX YYY ZZZ"
    4.     Array1 = Split(shName, Chr$(32))
    5.     Debug.Print Array1(2) 'contains ZZZ

    Here's another option:

    VB Code:
    1. Dim shName As String, Name2 As String, Name3 As String
    2.     shName = "XXX YYY ZZZ"
    3.     Name2 = Mid$(shName, 1 + InStr(shName, Chr$(32)))
    4.     Name3 = Mid$(Name2, 1 + InStr(Name2, Chr$(32)))
    5.     Debug.Print Name3

    Option #3:

    VB Code:
    1. Dim str1 As String
    2.     str1 = "XXX YYY ZZZ"
    3.     Debug.Print Mid(str1, WorksheetFunction.Find(Chr$(32), str1, 1 + InStr(str1, Chr$(32)) + 1))
    Last edited by VBAhack; Apr 20th, 2006 at 11:14 PM.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Location
    Montreal, Canada
    Posts
    152

    Re: Find specific data in sheet name

    Thanks a lot VBAhack

    really helpful what you gave me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width