Change Text Case to Upper

Peteor

Board Regular
Joined
Mar 16, 2018
Messages
152
Hey team! I have the following code:

Sub Bold_and_Red_Text()
'
' Converts all instances of the designated string, in all selected cells to Red & Bolds them.
'
' Keyboard Shortcut: Ctrl+Shift+Q
'
Application.ScreenUpdating = False
Dim Rng As Range
Dim cFnd As String
Dim xTmp As String
Dim x As Long
Dim m As Long
Dim y As Long
cFnd = InputBox("Enter the text string to highlight *NOTE* Input is case sensitive!")
y = Len(cFnd)
For Each Rng In Selection
With Rng
m = UBound(Split(Rng.Value, cFnd))
If m > 0 Then
xTmp = ""
For x = 0 To m - 1
xTmp = xTmp & Split(Rng.Value, cFnd)(x)
.Characters(Start:=Len(xTmp) + 1, Length:=y).Font.ColorIndex = 3
.Characters(Start:=Len(xTmp) + 1, Length:=y).Font.Bold = True
xTmp = xTmp & cFnd
Next
End If
End With
Next Rng
Application.ScreenUpdating = True

End Sub

What would you recommend modifying If I also wanted to be able to search for the word "shall", and it automatically find instances of "shall" & "Shall". It would then convert all of them to "SHALL" in addition to changing the color index / bold?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
I found my own solution. Please see the below, regardless though, thank you for reviewing.

Option Compare Text

Sub Bold_and_Red_Text()
'
' Converts all instances of the designated string, in all selected cells to Red & Bolds them.
'
' Keyboard Shortcut: Ctrl+Shift+Q
'
Application.ScreenUpdating = False
Dim Rng As Range
Dim cFnd As String
Dim xTmp As String
Dim x As Long
Dim m As Long
Dim y As Long
cFnd = InputBox("Enter the text string to highlight *NOTE* Input is case sensitive!")
y = Len(cFnd)
For Each Rng In Selection
With Rng
m = UBound(Split(Rng.Value, cFnd))
If m > 0 Then
xTmp = ""
For x = 0 To m - 1
xTmp = xTmp & Split(Rng.Value, cFnd)(x)

Rng.Replace What:=cFnd, Replacement:=UCase(cFnd)
.Characters(Start:=Len(xTmp) + 1, Length:=y).Font.ColorIndex = 3
.Characters(Start:=Len(xTmp) + 1, Length:=y).Font.Bold = True

xTmp = xTmp & cFnd
Next
End If
End With
Next Rng
Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,003
Messages
6,122,655
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top