+ Reply to Thread
Results 1 to 3 of 3

custom function to ucase first 2 letters

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-09-2013
    Location
    City, World
    MS-Off Ver
    Office 365
    Posts
    248

    custom function to ucase first 2 letters

    Hello, I want to create my own function which will take a text and convert the first 2 letter to upper case but this function is not working! Thank you.

    Function mytext(x As String) As String
        x = UCase(Left(x, 1)) & UCase(Left(x, 2)) & Left(x, Len(x) - 2)
        mytext = x
    End Function

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: custom function to ucase first 2 letters

    try
    Function mytext(x As String) As String
        x = UCase(Left(x, 1)) & UCase(mid(x,2,1)) & mid(x, 3, Len(x) - 2)
        mytext = x
    End Function
    or shorter and working also with shorter strings
    (deleted - see corrected version below)
    Last edited by Kaper; 03-04-2021 at 04:06 AM.
    Best Regards,

    Kaper

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: custom function to ucase first 2 letters

    Note I removed second version form above post.
    Here it is corrected:
    Function mytext(x As String) As String
      If Len(x) > 2 Then
        mytext = UCase(Left(x, 2)) & Mid(x, 3, Len(x) - 2)
      Else
        mytext = UCase(x)
      End If
    End Function

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Custom Format with Numbers and Letters?
    By anon12398 in forum Excel General
    Replies: 9
    Last Post: 03-07-2019, 06:49 AM
  2. [SOLVED] Apply UCASE Function
    By flindy87 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-08-2013, 08:24 AM
  3. Excel custom format with letters and numbers
    By pdrodrig in forum Excel General
    Replies: 1
    Last Post: 06-11-2009, 08:08 AM
  4. Custom sorting with Letters and Zeros
    By darkjedi in forum Excel General
    Replies: 3
    Last Post: 04-26-2006, 03:10 PM
  5. [SOLVED] How do I change letters at top of excel to custom headers
    By painintheoffice in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  6. How do I change letters at top of excel to custom headers
    By painintheoffice in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 AM
  7. How do I change letters at top of excel to custom headers
    By painintheoffice in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM

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