Forum Discussion

patrickjk69's avatar
patrickjk69
Copper Contributor
Dec 20, 2024
Solved

Find and replace with replacements in italics

Hi: I've created a pretty large spreadsheet listing a whole bunch of books in a library. Looks great, but there are a couple of issues I can't seem to resolve. The entries need the imprint to be in i...
  • HansVogelaar's avatar
    HansVogelaar
    Dec 26, 2024

    You need a VBA macro for this in Excel.

    Sub Italicize()
        Const strText = "London: Penguin Books"
        Dim rng As Range
        Dim adr As String
        Dim pos As Long
        Set rng = Selection.Find(What:=strText, LookAt:=xlPart)
        If Not rng Is Nothing Then
            Application.ScreenUpdating = False
            adr = rng.Address
            Do
                pos = InStr(rng.Value, strText)
                rng.Characters(Start:=pos, Length:=Len(strText)).Font.Italic = True
                Set rng = Selection.Find(What:=strText, After:=rng, LookAt:=xlPart)
                If rng Is Nothing Then Exit Do
            Loop Until rng.Address = adr
            Application.ScreenUpdating = True
        End If
    End Sub

     

Resources