Find Text in cell and bold that line

brainzlp

New Member
Joined
Jul 10, 2018
Messages
11
Hello everyone,

I have a cell with several lines, i would like to search for "1º", and when find bold that whole line.
I found a macro that finds a text and bold it: (But has a lot of uncessary stuff i don't need like input box and stuff., only need to find 1º and bold line )

Code:
Sub FindAndBold()'Updateby Extendoffice 20160711
    Dim xFind As String
    Dim xCell As Range
    Dim xTxtRg As Range
    Dim xCount As Long
    Dim xLen As Integer
    Dim xStart As Integer
    Dim xRg As Range
    Dim xTxt As String
    On Error Resume Next
    If ActiveWindow.RangeSelection.Count > 1 Then
      xTxt = ActiveWindow.RangeSelection.AddressLocal
    Else
      xTxt = ActiveSheet.UsedRange.AddressLocal
    End If
    Set xRg = Application.InputBox("Please select data range:", "Kutools for Excel", xTxt, , , , , 8)
    If xRg Is Nothing Then Exit Sub
    On Error Resume Next
    Set xTxtRg = Application.Intersect(xRg.SpecialCells(xlCellTypeConstants, xlTextValues), xRg)
    If xTxtRg Is Nothing Then
        MsgBox "There are no cells with text"
        Exit Sub
    End If
    xFind = Trim(Application.InputBox("What do you want to BOLD?", "Kutools for Excel", , , , , , 2))
    If xFind = "" Then
        MsgBox "No text was listed", vbInformation, "Kutools for Excel"
        Exit Sub
    End If
    xLen = Len(xFind)
    For Each xCell In xTxtRg
        xStart = InStr(xCell.Value, xFind)
        Do While xStart > 0
            xCell.Characters(xStart, xLen).font.Bold = True
            xCount = xCount + 1
            xStart = InStr(xStart + xLen, xCell.Value, xFind)
        Loop
    Next
    If xCount > 0 Then
        MsgBox "number of " & CStr(xCount) & " text be bolded!", vbInformation, "Kutools for Excel"
    Else
        MsgBox "Not find the specific text!", vbInformation, "Kutools for Excel"
    End If
End Sub

My Cell A1 is like this:
3º ABC
2º ABB
1º ACCC
5º ASDASD
5º ASDAS
6º ASDA

Essential what i need to when i find 1º bold that line.

Thanks for all your help
 
got the solution:

Code:
Option Explicit

Sub FindAndBold()
    Dim xFind As String
    Dim xLen As Integer
    Dim StartPos As Variant
    Dim strA As String
    Dim a As Variant
    strA = Range("V91").Value
    xFind = "1º*"
    For Each a In Split(strA, ChrW(10))
    If a Like xFind Then
        StartPos = InStr(strA, a)
        xLen = Len(a)
        Range("V91").Characters(StartPos, xLen).font.Bold = True
    End If
    Next a
    
End Sub


Sub test()
    Dim m As Object
    With CreateObject("VBScript.RegExp")
        .Global = True
        .MultiLine = True
        .Pattern = "^1" & ChrW(186) & ".*"
        For Each m In .Execute([V91])
            [V91].Characters(m.firstindex + 1, m.Length).font.Bold = True
        Next
    End With
End Sub

 2 ways both works
 
Upvote 0

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
That's exactly what i wanted, although i can't put this on column A, i need a specific cell cuz it will be variable. Right now i have in "V91"
Well it was in column A in post #1 ;)
But adapted to that single cell my code would become
Code:
Sub Bold_1deg()
  Dim RX As Object
  Dim itm As Variant
  
  Set RX = CreateObject("VBScript.RegExp")
  RX.Global = True
  RX.MultiLine = True
  RX.Pattern = "^1º.*$"
    For Each itm In RX.Execute(Range("V91").Value)
      Range("V91").Characters(Start:=itm.firstindex + 1, Length:=itm.Length).Font.Bold = True
    Next itm
  Application.ScreenUpdating = True
End Sub
.. which is pretty similar to what was subsequently posted in the other forum. :)
 
Upvote 0
good morning. Does the macro count the number of times a value / string is repeated within a file in a folder?
If I have the following column headers:
file name - value - number of times the value is repeated

the macro checks inside the folder for each file whose name is indicated in the first column the value indicated in the second one and returns the number of times this value or scringe occurs?

Thank you

<svg class="SnapLinksHighlighter" xmlns="http://www.w3.org/2000/svg"> <rect width="0" height="0"></rect> <!-- Used for easily cloning the properly namespaced rect --> </svg>
 
Upvote 0
yes, it's pretty the same

Thanks for your time and help, was a big help. couldn't do this solution by myself :D
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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