Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with getting a partial part of a string 1

Status
Not open for further replies.

atray04

Programmer
Dec 29, 2003
112
US
I have a case statement and I am trying to search for part of a sentence in a string so that I can use that in my case. I am thinking that I will need to use a length function and get the part of gthe string I want that way. Heres the code that I am using minus the length method.
fName = c:\file.xls
sheetName = fName 'fName has the whole string and sheetName should equal the partial string which is file
Select Case sheetName
Case file
ws.Name = "file"
Case dinner
ws.Name = "Dinner"
Case nc
ws.Name = "NC"
Case pc
ws.Name = "PC"
Case Else
'more possibilities?
End Select
 
Hi,

Here's a way using instr...
Code:
    Dim sName(3)
    sName(0) = "file"
    sName(1) = "Dinner"
    sName(2) = "NC"
    fname = "c:\file.xls"
    For i = 0 To 2
        If InStr(fname, sName(i)) > 0 Then
            ws.Name = sName(i)
            Exit For
        End If
    Next
:)



Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884

Skip,
 
Use can try the mid function:

mid(<your proposition>,<length of fragment>,<starting position in your proposition>)

Debugging is Futile!
 
yea that will work, but the inStr applys more to what im doing. Thanxs though
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top