This piece of VBA code below, will search for the word
"Total" and set the font of the next column to bold.
The VBA code can be used or tweak to search any word on the
worksheet and set the next value of the next column to bold also.
Or do other desired VBA operation, like deleting the next
column value.
Here's the code:
===========================
Sub Bold_Total()
Dim StrSearch As String
Dim xRng1 As Range
Dim xRng2 As Range
Dim xInt As Integer
Dim strAddress As Variant
StrSearch = "Total"
With Worksheets(1).UsedRange
Set xRng1 = .Find(StrSearch, , xlValues, xlPart)
If Not xRng1 Is Nothing Then
strAddress = xRng1.Address
Do
Set xRng1 = .FindNext(xRng1)
'MsgBox xRng1.Address
xInt = Range(xRng1.Address).Row
'MsgBox xInt
Cells((xInt), 1).Select
'Just for example purposes will set the value of the offset cell to the found row number
'Remove line below if have actual data
ActiveCell.Offset(, columnOffset:=1).Value = xInt
'set the offset column to bold
ActiveCell.Offset(, columnOffset:=1).Font.Bold = True
'Remove the "'" hypen or the comment to let VBA execute the line
'To delete the next column value set this line:
'ActiveCell.Offset(, columnOffset:=1).Value = ""
'Loop until it returns to the first found address
Loop Until xRng1.Address = strAddress
End If
End With
End Sub
===========================
Cheers..Enjoy VBA coding..
click on labels below for more VBA..
==============================
Educational App for Android Kids:
https://play.google.com/store/apps/details?id=com.letsmultiply
==============================
Educational App for Android Kids:
https://play.google.com/store/apps/details?id=com.letsmultiply
Comments
Post a Comment