+ Reply to Thread
Results 1 to 13 of 13

Upper and Lower Cases of Text

Hybrid View

  1. #1
    Registered User
    Join Date
    08-08-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    2

    Upper and Lower Cases of Text

    Hi, I need a formula to convert a text in all upper cases into lower cases except for the first letter in the first word after each equal sign. However, the text before the equal sign must still be in capital letters. I currentrly use the function PROPER which did not give me the desired result. Please see attachment.
    Attached Files Attached Files

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Upper and Lower Cases of Text

    I could offer you a formula that would deal with ONE = sign and make everything CAPS before it and Proper after it. For delimited strings like you are demonstrating I would resort to VBA programming to resolve this scenario.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Forum Contributor
    Join Date
    08-11-2012
    Location
    bengalur
    MS-Off Ver
    Excel 2003, 2007
    Posts
    152

    Re: Upper and Lower Cases of Text

    This is above formula used for the first BUS=BUSINESS, RES=RESIDENTIAL
    =UPPER(MID(B2,1,FIND("=",B2)))&PROPER(MID(B2,(FIND("=",B2)+1),(FIND(",",B2)-FIND("=",B2))))&UPPER(MID(B2,FIND(",",B2)+1,FIND("=",B2,(FIND("=",B2)))))&PROPER(MID(B2,FIND("=",B2,(FIND("=",B2))),LEN(B2)+1-FIND("=",B2,FIND("=",B2))))

  4. #4
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: Upper and Lower Cases of Text

    Without VBA, this would only be possible if you had a fixed number of entries in each cell in Column A (i.e. you had the same number of "=" signs in every cell). Without this knowledge, there is no formula that I am aware of that will accomplish what it is that you are trying to achieve unfortunately.

    To achieve the result in VBA, place a button onto your worksheet, and place the following code into your button's Click event (my button is called "CommandButton1"):
    Private Sub CommandButton1_Click()
        Dim i, j As Integer
        Dim eqPos() As Integer
        Dim comPos() As Integer
        Dim strRequired As String
        
        'Initialise the array's containing the position of each "=" and ","
        ReDim eqPos(0)
        ReDim comPos(0)
        
        With ActiveSheet
            'Cycle through every populated cell in Column A
            For i = 2 To .Cells(.Rows.Count, "A").End(xlUp).Row
                'Cycle through every character in the cell value
                For j = 1 To Len(.Cells(i, "A").Value)
                    If Mid(.Cells(i, "A").Value, j, 1) = "=" Then
                        'If the character is "="
                        ReDim Preserve eqPos(UBound(eqPos) + 1)
                        
                        eqPos(UBound(eqPos)) = j
                    End If
                    
                    If Mid(.Cells(i, "A").Value, j, 1) = "," Then
                        'If the character is ","
                        ReDim Preserve comPos(UBound(comPos) + 1)
                        
                        comPos(UBound(comPos)) = j
                    End If
                Next j
                
                'Cycle through every segment of the string, separated by "="
                For j = 1 To UBound(eqPos)
                    If j = 1 Then
                        'If this is the first segment
                        If UBound(eqPos) > 1 Then
                            'If this is the first of multiple "="
                            strRequired = Mid(.Cells(i, "A").Value, 1, eqPos(j) + 1)
                        Else
                            'If this is the only "="
                            strRequired = Mid(.Cells(i, "A").Value, 1, eqPos(j) + 1) _
                                & LCase(Mid(.Cells(i, "A").Value, eqPos(j) + 2, Len(.Cells(i, "A").Value) - eqPos(j) - 1))
                        End If
                    Else
                        'If this is not the first segment
                        If j < UBound(eqPos) Then
                            'If this is not the last segment
                            strRequired = strRequired _
                                & LCase(Mid(.Cells(i, "A").Value, eqPos(j - 1) + 2, comPos(j - 1) - eqPos(j - 1) - 1)) _
                                & Mid(.Cells(i, "A").Value, comPos(j - 1) + 1, eqPos(j) + 1 - comPos(j - 1))
                        Else
                            'If this is the last segment
                            strRequired = strRequired _
                                & LCase(Mid(.Cells(i, "A").Value, eqPos(j - 1) + 2, comPos(j - 1) - eqPos(j - 1) - 1)) _
                                & Mid(.Cells(i, "A").Value, comPos(j - 1) + 1, eqPos(j) + 1 - comPos(j - 1)) _
                                & LCase(Mid(.Cells(i, "A").Value, eqPos(j) + 2, Len(.Cells(i, "A").Value) - eqPos(j) - 1))
                        End If
                    End If
                Next j
                
                'Write the appropriately formatted string to the same row in column D
                .Cells(i, "D").Value = strRequired
                
                'Reset the variables for the next row
                strRequired = ""
                ReDim eqPos(0)
                ReDim comPos(0)
            Next i
        End With
    End Sub

  5. #5
    Forum Contributor
    Join Date
    06-26-2013
    Location
    LAX
    MS-Off Ver
    Excel 2007,Excel 2010
    Posts
    363

    Re: Upper and Lower Cases of Text

    Yes, As JBeaucaire says VBA would be the solution.
    But if you would like to have a non VBA solution, see if the attached kind of work around helps.
    Attached Files Attached Files

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Upper and Lower Cases of Text

    Try this UDF which will work with N number of permutation combination.

    Function SpecificTitleCase(v As Variant) 'By :) Sixthsense :)
    Dim vSplit As Variant, iLoc As Integer, i As Integer
    Dim sTemp As String, sConv As String, sData As String
    
    vSplit = Split(v, ",")
    
    For i = LBound(vSplit) To UBound(vSplit)
        sTemp = vSplit(i)
        iLoc = InStr(sTemp, "=")
        If iLoc Then
            sConv = StrConv(Mid(sTemp, iLoc + 1, 255), vbProperCase)
            sConv = Left(sTemp, iLoc) & sConv
            sData = sData & sConv & ", "
        Else
            sData = sData & sTemp & ", "
        End If
    Next i
    
    SpecificTitleCase = sData
    
    If Len(sData) > 0 Then SpecificTitleCase = Left(sData, Len(sData) - 2)
        
    End Function
    Formula: copy to clipboard
    =SpecificTitleCase(A2)


    Or

    Formula: copy to clipboard
    =SpecificTitleCase("CA=CALIFORNIA, NY=NEW YORK, FL=FLORIDA")


    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  7. #7
    Forum Contributor
    Join Date
    07-02-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2003 and 2007
    Posts
    197

    Re: Upper and Lower Cases of Text

    That code was very impressing Sixthsense!!!

  8. #8
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Upper and Lower Cases of Text

    Thanks for the feedback and rep

    But the code of TMShucks is having lot more functionalities/features than my suggested code

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,613

    Re: Upper and Lower Cases of Text

    If you do want a VBA function, then maybe this:

    Option Explicit
    
    Function TMS(rInput As Range, _
                 Optional sSep1 = ",", _
                 Optional sSep2 = "=" _
                 ) As String
    ' TMShucks Excel Aid on the Excel Forum
    ' Upper and Lower Cases of Text
    ' http://www.excelforum.com/excel-formulas-and-functions/946009-upper-and-lower-cases-of-text.html
    ' UDF to split cells and convert to upper case / proper case
    ' VBA call example: Debug.Print TMS(Range("A2"))
    ' Worksheet example: =TMS(A2)
    ' Worksheet example: =TMS(A2,",")
    ' Worksheet example: =TMS(A6,,"|")
    
    Dim vInput              ' variant to split input range
    Dim sOutput As String   ' output string
    Dim vBA                 ' variant to split befor and after "="
    Dim i As Long           ' Loop Counter
    
    On Error GoTo lblOOPS
    ' split the original cell contents using the separator
    vInput = Split(rInput.Value, sSep1)
    ' then, loop through the cell values
    For i = LBound(vInput) To UBound(vInput)
        ' split the range, if possible
        vBA = Split(vInput(i), sSep2)
        vBA(0) = UCase(vBA(0))
        vBA(1) = Application.WorksheetFunction.Proper(vBA(1))
        vInput(i) = Join(vBA, sSep2)
    Next 'i
    sOutput = Join(vInput, sSep1)
    TMS = sOutput
    Exit Function
    lblOOPS:
    TMS = rInput
        
    End Function
    
    Sub sTestTMS()
    
    Debug.Print TMS(Range("A2"))
    
    End Sub

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  10. #10
    Registered User
    Join Date
    08-08-2013
    Location
    US
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Upper and Lower Cases of Text

    Thank you all for your suggestions. For now, I will use the Excel formula since I'm on tight deadline and VBA for the next project.

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Upper and Lower Cases of Text

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

  12. #12
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Upper and Lower Cases of Text

    Just for fun this formulae approach can be extended to suit any length of string.

    Name:="Split_Str"
    Refers to:=
    Formula: copy to clipboard
    =INDEX(IF((MID(","&Sheet1!$A2&",",ROW(INDIRECT("1:"&LEN(","&Sheet1!$A2&","))),1)="=")+(MID(","&Sheet1!$A2&",",ROW(INDIRECT("1:"&LEN(","&Sheet1!$A2&","))),1)=","),ROW(INDIRECT("1:"&LEN(","&Sheet1!$A2&","))),""),,1)

    Then in C2, Drag across as far as required to split your longest string, then Down
    Formula: copy to clipboard
    =IFERROR(IF(ISNUMBER(FIND("=",MID($A2,SMALL(Split_Str,COLUMNS($C:C)),SMALL(Split_Str,COLUMNS($C:D))-SMALL(Split_Str,COLUMNS($C:C))))),MID($A2,SMALL(Split_Str,COLUMNS($C:C)),SMALL(Split_Str,COLUMNS($C:D))-SMALL(Split_Str,COLUMNS($C:C))),PROPER(MID($A2,SMALL(Split_Str,COLUMNS($C:C)),SMALL(Split_Str,COLUMNS($C:D))-SMALL(Split_Str,COLUMNS($C:C))))),"")

    Concatenate the results in B2
    =
    Formula: copy to clipboard
    C2&D2&E2&F2&G2&H2&I2&J2&K2&L2&M2&N2
    Attached Files Attached Files
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,613

    Re: Upper and Lower Cases of Text

    You're welcome. Thanks for the rep.


    Seems a shame not to use the code solution when all you have to do is copy and paste the code into a standard module. It will work "out of the box".

    But, your choice. Good luck with your project.


    Regards, TMS

+ 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. [SOLVED] How to convert a column of text to upper and lower case?
    By jewell b in forum Excel General
    Replies: 1
    Last Post: 08-06-2006, 04:10 AM
  2. How to test text case for Upper/Lower/Proper
    By JS in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-22-2006, 08:05 PM
  3. Replies: 2
    Last Post: 12-09-2005, 05:15 AM
  4. Replies: 14
    Last Post: 08-25-2005, 10:05 PM
  5. [SOLVED] How do I convert all upper case excel sheet into upper and lower .
    By DebDay in forum Excel General
    Replies: 1
    Last Post: 03-09-2005, 05:06 PM

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