VBA Excel 2016 - Upper Case and Font size lines required...

Dan1000

Board Regular
Joined
Nov 4, 2006
Messages
210
The following code works fine, only I would like to insert a line of code to change the text to Upper case and another line to change the size of the font.

Any help would be much appreciated:



Dim i As Integer


Text(1) = "text1"
Text(2) = "text2"
Text(3) = "text3"


For i = LBound(Text) To UBound(Text)
For Each rCell In Range("A2:m100")
sToFind = Text(i)
iSeek = InStr(1, rCell.Value, sToFind)
Do While iSeek > 0
rCell.Characters(iSeek, Len(sToFind)).Font.Bold = True
rCell.Characters(iSeek, Len(sToFind)).Font.Underline = True
>
>

iSeek = InStr(iSeek + 1, rCell.Value, sToFind)
Loop
Next rCell
Next i


End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try
Code:
Do While iSeek > 0
With rCell.Characters(iSeek, Len(sToFind)).Font
   .Bold = True
   .Underline = xlSingle
   .Size = 16
End With
   rCell.Replace sToFind, UCase(sToFind)

iSeek = InStr(iSeek + 1, rCell.Value, sToFind)
Loop
 
Upvote 0
Thank you for the replies, will view yours Joe4. I tried yours Fluff and its doing something but maybe due to my missing the top 3 lines of the Sub that its not working correctly...sorry, the Sub should have been as follows:


Code:
Sub Find_and_Bold()
Dim rCell As Range, sToFind As String, iSeek As Long
Dim Text(1 To 3) As String
Dim i As Integer




Text(1) = "text1"
Text(2) = "text2"
Text(3) = "text3"






For i = LBound(Text) To UBound(Text)
    For Each rCell In Range("A2:m100")
            sToFind = Text(i)
            iSeek = InStr(1, rCell.Value, sToFind)
    
    Do While iSeek > 0
With rCell.Characters(iSeek, Len(sToFind)).Font
   .BOLD = True
   .Underline = xlSingle
   .Size = 16
End With
   rCell.Replace sToFind, UCase(sToFind)


iSeek = InStr(iSeek + 1, rCell.Value, sToFind)
Loop
    
    
    
    
    
    
    
    Next rCell
Next i




End Sub
 
Last edited by a moderator:
Upvote 0
In what way isn't it working?

Also when posting code please use code tags, the # icon in the reply window.
 
Upvote 0
Hi Fluff

Its raised the text size in a few cells in columns H and M and looks to have underlined most if not all the other text items and has made all text in all cells bold.

Also, can you send an example of the hash symbol in its place which you mention should be used - never done that in the past but would like to keep to any rules there are


Any further help grateful received, thank you
 
Upvote 0
Try it like
Code:
   For i = LBound(Text) To UBound(Text)
      For Each rCell In Range("A2:m100")
         sToFind = Text(i)
         iSeek = InStr(1, rCell.Value, sToFind, 1)
         
         Do While iSeek > 0
            rCell.Replace sToFind, UCase(sToFind)
            
            With rCell.Characters(iSeek, Len(sToFind)).Font
               .Bold = True
               .Underline = xlSingle
               .Size = 16
            End With
            
            iSeek = InStr(iSeek + 1, rCell.Value, sToFind)
         Loop
      Next rCell
   Next i
Re the # icon. Along the top of the reply window there are various icons, the last of which is the #, if you click on that you will see two code tags appear. Simply paste your code between them.
 
Upvote 0
Thats done it, thank you so much for your help Fluff (and advice regarding the code insertion technique)!

Dan
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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