How to Bold the First and Last Sentence of Text in Multiple Cells

xSonicspeedx

New Member
Joined
Nov 13, 2023
Messages
3
Office Version
  1. 365
Platform
  1. Windows
I have 750 Fact Patterns with Questions in Column A with the Answers in Column B. Each fact pattern is approximately 6-10 sentences in addition to a trailing question. I am trying to easily identify the fact pattern by the first sentence and the question for all 750 questions for purposes of memorization studying through association. Many fact patterns are similar with slight variations.

Can someone help me create formula which could be used to bold the first or second sentence in the fact pattern and the trailing question (the last sentence)? (Example of my layout below)

1699903111198.png
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I don't believe you can do that with a formula, but should be able to do it with vba code. However, your example and explanation isn't clear because you only show one bold portion, plus using jargon that you are familiar with doesn't help others understand if they don't know the jargon. As old as I am, I've never heard of a "fact pattern" but I think I'm not too bad figuring out code solutions.
 
Upvote 0
Okay, my question is... "How do I Bold the last sentence (which ends in a question mark (?)) (the string of text between the . and ?) of 750 cells which contain similar strings of text and the first sentence (which ends in a period not including the #) of every problem I have typed out in Excel using a formula?
- The bolded portion in my example is just a heading and not of concern.
 
Upvote 0
If you want a formula I leave that to those who are good at them. I put this in F1 on sheet 008
... else. Is the client correct?
and ran this simple code against the cell. Upon second thought it can probably just be a sub; all depends on how it would be used, if at all. It's incomplete because it doesn't encompass 700 rows but I have no clue what your sheet looks like so the best I can do is demonstrate that it's doable.
VBA Code:
Function boldLastLine(strIn As String)
Dim lngPos As Long
Dim rng As Range

Set rng = Sheets("008").Range("F1")
lngPos = InStrRev(rng, ".")
rng.Characters(Start:=lngPos + 2).Font.Bold = True

End Function
and got this
… else. Is the client correct?
 
Upvote 0
You cannot partially format the numerical values in the cell and the texts that are the result of the formula.
You can partially format only fixed text values (including numbers stored in the cell as text).
Assuming:
1. there can be cells with headings in column A. In that case, the entire cell must be bolded before using the macro.
2. you want to bold the second sentence in the cell (because the first is a numbering) and the last sentence that ends with a character other than a dot.
3. if the cell under investigation already contains partial text formatting, it will be skipped.

Try the following macro:
VBA Code:
Sub AAA()
    Dim v As Variant
    Dim i As Long, j As Long
    Dim k As Long
    Dim FirstSentence As String
    Dim LastSentence As String
    Dim strVal As String
    Dim lRow As Long

    lRow = Cells(Rows.Count, 1).End(xlUp).Row

    For k = 1 To lRow
        If Not Cells(k, 1).Font.Bold Then
            strVal = Cells(k, 1).Value

            v = Split(strVal, ".")

            FirstSentence = v(1) & "."
            i = Len(v(0)) + 2
            j = Len(v(1)) + 1

            Cells(k, 1).Characters(Start:=i, Length:=j).Font.Bold = True

            LastSentence = v(UBound(v))
            j = Len(LastSentence)
            i = Len(strVal) - Len(LastSentence) + 1

            Cells(k, 1).Characters(Start:=i, Length:=j).Font.Bold = True
        End If
    Next k

End Sub
Artik
 
Upvote 0
Another macro to try

VBA Code:
Sub Add_Bold()
  Dim r As Range
  Dim Pos1 As Long
  
  For Each r In Range("A2", Range("A" & Rows.Count).End(xlUp))
    Pos1 = InStr(1, r.Value, " ") + 1
    r.Characters(Pos1, InStr(Pos1, r.Value, ".") - Pos1 + 1).Font.Bold = True
    Pos1 = InStrRev(r.Value, ". ") + 2
    r.Characters(Pos1, Len(r.Value) - Pos1 + 1).Font.Bold = True
  Next r
End Sub

My test data before:

1700012576887.png


After:

1700012634759.png
 
Upvote 0
Thank you guys, I figured out how to use the VBA and your suggestions worked great!
 
Upvote 0
You're welcome. Glad we could help. Thanks for the follow-up. :)
 
Upvote 0

Forum statistics

Threads
1,215,086
Messages
6,123,038
Members
449,092
Latest member
ikke

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