+ Reply to Thread
Results 1 to 8 of 8

Extract part of a Worksheet name.

  1. #1
    Forum Contributor
    Join Date
    01-06-2004
    Location
    Carbondale CO
    Posts
    245

    Extract part of a Worksheet name.

    Hi,
    I’m having problems extracting part of a worksheet name to compare to a text string.
    I’m getting a 438 error Object doesn’t support this property or method. I have looked in help and the Mid function doesn’t seem to be supported in VBA, but I’m at a loss for a substitute. I just need to check if the first three letters of the worksheet name = CWR

    Here is an excerpt of my code.

    ElseIf ActiveSheet.Name = "CWR LOG" Then
    ComboBoxTopics.ListIndex = 2
    ElseIf Application.WorksheetFunction.Mid(ActiveSheet.Name, 1, 3) = "CWR" Then 'This is where the error hits.
    ComboBoxTopics.ListIndex = 10
    Casey

  2. #2
    excelent
    Guest

    RE: Extract part of a Worksheet name.

    try
    ElseIf Mid(ActiveSheet.Name, 1, 3) = "CWR" Then


    "Casey" skrev:

    >
    > Hi,
    > I’m having problems extracting part of a worksheet name to compare to a
    > text string.
    > I’m getting a 438 error Object doesn’t support this property or method.
    > I have looked in help and the Mid function doesn’t seem to be supported
    > in VBA, but I’m at a loss for a substitute. I just need to check if the
    > first three letters of the worksheet name = CWR
    >
    > Here is an excerpt of my code.
    >
    > ElseIf ActiveSheet.Name = "CWR LOG" Then
    > ComboBoxTopics.ListIndex = 2
    > ElseIf Application.WorksheetFunction.Mid(ActiveSheet.Name, 1, 3) =
    > "CWR" Then 'This is where the error hits.
    > ComboBoxTopics.ListIndex = 10
    >
    >
    > --
    > Casey
    >
    >
    > ------------------------------------------------------------------------
    > Casey's Profile: http://www.excelforum.com/member.php...fo&userid=4545
    > View this thread: http://www.excelforum.com/showthread...hreadid=562204
    >
    >


  3. #3
    JE McGimpsey
    Guest

    Re: Extract part of a Worksheet name.

    Use the VBA Mid() function...

    ElseIf Mid(ActiveSheet.Name, 1, 3) = "CWR" Then

    Worksheet functions that duplicate VBA functions aren't accessible in
    VBA.

    In article <[email protected]>,
    Casey <[email protected]> wrote:

    > Hi,
    > I’m having problems extracting part of a worksheet name to compare to a
    > text string.
    > I’m getting a 438 error Object doesn’t support this property or method.
    > I have looked in help and the Mid function doesn’t seem to be supported
    > in VBA, but I’m at a loss for a substitute. I just need to check if the
    > first three letters of the worksheet name = CWR
    >
    > Here is an excerpt of my code.
    >
    > ElseIf ActiveSheet.Name = "CWR LOG" Then
    > ComboBoxTopics.ListIndex = 2
    > ElseIf Application.WorksheetFunction.Mid(ActiveSheet.Name, 1, 3) =
    > "CWR" Then 'This is where the error hits.
    > ComboBoxTopics.ListIndex = 10


  4. #4
    Forum Contributor
    Join Date
    01-06-2004
    Location
    Carbondale CO
    Posts
    245
    excelent & JE McGimpsey,
    Thanks for the replies. Works fine now.

  5. #5

    Re: Extract part of a Worksheet name.

    Casey

    Here is a snipet of code I use for looping through one of my workbooks
    searching for sheet names. Note the use of the wildcard.

    Alan

    Dim sht as Worksheet
    For Each Sht In Wkbk.Sheets
    If Sht.Name Like "*My_Sheet" Then
    'your code here
    End If
    Next Sht


    Casey wrote:
    > Hi,
    > I'm having problems extracting part of a worksheet name to compare to a
    > text string.
    > I'm getting a 438 error Object doesn't support this property or method.
    > I have looked in help and the Mid function doesn't seem to be supported
    > in VBA, but I'm at a loss for a substitute. I just need to check if the
    > first three letters of the worksheet name = CWR
    >
    > Here is an excerpt of my code.
    >
    > ElseIf ActiveSheet.Name = "CWR LOG" Then
    > ComboBoxTopics.ListIndex = 2
    > ElseIf Application.WorksheetFunction.Mid(ActiveSheet.Name, 1, 3) =
    > "CWR" Then 'This is where the error hits.
    > ComboBoxTopics.ListIndex = 10
    >
    >
    > --
    > Casey
    >
    >
    > ------------------------------------------------------------------------
    > Casey's Profile: http://www.excelforum.com/member.php...fo&userid=4545
    > View this thread: http://www.excelforum.com/showthread...hreadid=562204



  6. #6
    Forum Contributor
    Join Date
    01-06-2004
    Location
    Carbondale CO
    Posts
    245
    Alan,
    Thanks for the reply. If you look at the entire thread; I got the answer I needed, however I think your reply may help with another problem I have with a different project. Thanks again.

  7. #7
    Dove
    Guest

    Re: Extract part of a Worksheet name.

    Two more string functions that I find useful are:

    'For what you are looking for
    If Left$(ActiveSheet.Name,3) = "CWR" Then

    It's related funcion is Right$. I know that these are supported through all
    versions of Excel VBA I have worked with, up through 2003 as carried over
    functions from the days of DOS Basic. I believe that you can leave off the
    $ but I use it as a habit from the old days.

    David

    "Casey" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Alan,
    > Thanks for the reply. If you look at the entire thread; I got the
    > answer I needed, however I think your reply may help with another
    > problem I have with a different project. Thanks again.
    >
    >
    > --
    > Casey
    >
    >
    > ------------------------------------------------------------------------
    > Casey's Profile:
    > http://www.excelforum.com/member.php...fo&userid=4545
    > View this thread: http://www.excelforum.com/showthread...hreadid=562204
    >




  8. #8
    Forum Contributor
    Join Date
    01-06-2004
    Location
    Carbondale CO
    Posts
    245
    David,
    Thanks for the insights. I wish I had started this whole programming stuff in my younger days so I would have some habits from the old days. As it is; I'm old and all of my habits are bad period. <vbg> Thanks again.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1