All text lowercase before a specific character

Brian F

Active Member
Joined
Aug 31, 2009
Messages
256
Excel 2010, Windows 8: I have this code that changes all of the text in a range to Not Bold, then goes through the range line by line and changes everything before a colon to Bold (a colon appears in each statement). At the present time each word before the colon begins with a Capital letter. I would now like to make everything before the colon lowercase . Can someone help me with this?

Sub Bold_To_Colon()

'Makes everything NOT bold then,
'Makes all the text before the colon bold

Dim c As Range, x As Long

Range("AS18:CC617").Select
Selection.Font.Bold = False

For Each c In Range("AS18:AS" & Range("AS" & Rows.Count).End(xlUp).row)
x = InStr(c, ":")
c.Font.Bold = False
If x > 0 Then c.Characters(1, x).Font.Bold = True
Next
End Sub
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,718
Office Version
2010
Platform
Windows
Untested:

Code:
Sub BoldToColon()
    Dim cell        As Range
    Dim i           As Long

    Range("AS18:CC617").Font.Bold = False

    With Range("AS18", Cells(Rows.Count, "AS"))
        .Font.Bold = False

        For Each cell In .Cells
            i = InStr(cell.Value, ":")

            If i Then
                cell.Value = LCase(Left(cell.Value, i)) & Mid(cell.Value, i + 1)
                cell.Characters(1, i).Font.Bold = True
            End If
        Next cell
    End With
End Sub
 

Brian F

Active Member
Joined
Aug 31, 2009
Messages
256
That works perfectly! Thank you so much shg. I now need to make the fist letter of each string a CAP. Do you have the time to show me how?
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,718
Office Version
2010
Platform
Windows
Still untested:

Code:
Sub BoldToColon()
    Dim cell        As Range
    Dim i           As Long
    Dim s           As String

    Range("AS18:CC617").Font.Bold = False

    With Range("AS18", Cells(Rows.Count, "AS"))
        .Font.Bold = False

        For Each cell In .Cells
            s = cell.Value
            i = InStr(s, ":")

            If i Then
                s = UCase(Left(cell.Value, 1)) & _
                    LCase(Mid(s, 2, i - 1)) & _
                    Mid(cell.Value, i + 1)
                cell.Value = s
                cell.Characters(1, i).Font.Bold = True
            End If
        Next cell
    End With
End Sub
 

Brian F

Active Member
Joined
Aug 31, 2009
Messages
256
Again, that works perfectly. While I was waiting I figured out a solution for myself but yours is vastly more elegant. Thank you for your help. That wraps up a project for me.
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,718
Office Version
2010
Platform
Windows
You're welcome.
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,718
Office Version
2010
Platform
Windows
Clenaup:

Code:
Sub BoldToColon()
    Dim cell        As Range
    Dim i           As Long
    Dim s           As String

    Range("AS18:CC617").Font.Bold = False

    With Range("AS18", Cells(Rows.Count, "AS"))
        .Font.Bold = False

        For Each cell In .Cells
            s = cell.Value
            i = InStr(s, ":")

            If i Then
                s = UCase(Left(s, 1)) & _
                    LCase(Mid(s, 2, i - 1)) & _
                    Mid(s, i + 1)
                cell.Value = s
                cell.Characters(1, i).Font.Bold = True
            End If
        Next cell
    End With
End Sub
 

Forum statistics

Threads
1,082,387
Messages
5,365,155
Members
400,826
Latest member
dnathanson

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top