+ Reply to Thread
Results 1 to 3 of 3

.Name case sensitive

  1. #1
    CinqueTerra
    Guest

    .Name case sensitive

    As part of a Print Macro, I am populating a list box with all range names
    beginning with "prt1". In testing my macro, I noted that it was case
    sensitive ("prt1 vs Prt1"). I've handled this with an OR statement. I'd
    like a more robust solution which handles all the possible upper/lower case
    combinations of prt1. Thanks in advance!

    Here is my code:

    Private Sub UserForm_Initialize()
    Dim nme As Name

    With lstP1
    For Each nme In ActiveWorkbook.Names
    If Left(nme.Name, 4) = "Prt1" Or Left(nme.Name, 4) = "prt1" Then
    .AddItem nme.Name
    End If
    Next nme
    End With


  2. #2
    Bill Martin
    Guest

    Re: .Name case sensitive

    CinqueTerra wrote:
    > As part of a Print Macro, I am populating a list box with all range names
    > beginning with "prt1". In testing my macro, I noted that it was case
    > sensitive ("prt1 vs Prt1"). I've handled this with an OR statement. I'd
    > like a more robust solution which handles all the possible upper/lower case
    > combinations of prt1. Thanks in advance!
    >
    > Here is my code:
    >
    > Private Sub UserForm_Initialize()
    > Dim nme As Name
    >
    > With lstP1
    > For Each nme In ActiveWorkbook.Names
    > If Left(nme.Name, 4) = "Prt1" Or Left(nme.Name, 4) = "prt1" Then
    > .AddItem nme.Name
    > End If
    > Next nme
    > End With
    >



    How about:

    If ucase(Left(nme.Name, 4)) = "PRT1" Then

    Bill

  3. #3
    Dave Peterson
    Guest

    Re: .Name case sensitive

    Another option is to put:

    Option Compare Text

    At the top of the module.

    If you have lots of code with lots of comparisons (and case really shouldn't
    matter), it might be the easiest fix.



    CinqueTerra wrote:
    >
    > As part of a Print Macro, I am populating a list box with all range names
    > beginning with "prt1". In testing my macro, I noted that it was case
    > sensitive ("prt1 vs Prt1"). I've handled this with an OR statement. I'd
    > like a more robust solution which handles all the possible upper/lower case
    > combinations of prt1. Thanks in advance!
    >
    > Here is my code:
    >
    > Private Sub UserForm_Initialize()
    > Dim nme As Name
    >
    > With lstP1
    > For Each nme In ActiveWorkbook.Names
    > If Left(nme.Name, 4) = "Prt1" Or Left(nme.Name, 4) = "prt1" Then
    > .AddItem nme.Name
    > End If
    > Next nme
    > End With


    --

    Dave Peterson

+ 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