SOLVED

Excel Autocorrect Formatting

Copper Contributor

Is there a way to have Excel autocorrect the formatting of a word or phrase to italics? For example I'm trying to correct CAL to CALIFORNIA in italics. In Word, it's pretty straightforward, but there doesn't seem to be a way to do it in Excel.

 

I'd also accept any workarounds, for example if CAL autocorrected to CALIFORNIA, and then there was a way to automatically recognize CALIFORNIA and make it CALIFORNIA.

 

Any help would be greatly appreciated!

8 Replies
Hi Ryan. There are any number of ways depending on how you are doing it. Could you upload a workbook sample of what you are after ? Makes it easier to get the right answer for you... :)
Hi Cambosity, thank for the quick response!

I can't upload anything really, confidential stuff. But it really is a very simple chart that I'm using as a board for a presentation. Participants will ask me to fill in the chart with various phrases, such as CALIFORNIA DREAMING or something similar. So I've created autocorrect shorthands such as CAL so I can better keep up with what they are saying. For some of the phrases, I want them to appear on the board in italics automatically.

In Word, you can easily just select the word in italics and create a shorthand for that, but the same functionality doesn't exist in Excel.
best response confirmed by Ryan_Holtz (Copper Contributor)
Solution

@Ryan_Holtz 

This doesn't exist in Excel since, unlike Word, text processing is not its primary purpose.

You might use VBA code. In the attached workbook, Sheet1 will replace some abbreviations and italicize the replacement matching the entire cell. Sheet2 will do the same for part of the cell.

You'll have to allow macros.

The code is in the worksheet modules - right-click a sheet tab and select View Code from the context menu to see and edit it.

This is exactly what I was looking for! Thank you so much.

Apologies for being so code-illiterate, but is there also a way to have certain words be changed to not be italics? So basically run two VBA codes at the same time, one that changes it to italics, and one that changes it from italics to no italics?

@Ryan_Holtz 

The current code runs automatically when you enter something in a cell.

 

Removing Italics seems to be more suitable for a macro to be run separately. Or do you disagree?

Totally agreed, I created a new line of code that removes italics, but I just need both of them to work together. Is there a way to do that?

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim arrFind
Dim arrReplace
Dim i As Long
If Target.CountLarge > 1 Then Exit Sub
' Modify and expand the arrays as needed
arrFind = Array("CAL", "ORE")
arrReplace = Array("CALIFORNIA DREAMING", "OREGON TRAIL")
Application.EnableEvents = False
On Error GoTo ExitHere
For i = 0 To UBound(arrFind)
If Target.Value = arrFind(i) Then
Target.Value = arrReplace(i)
Target.Font.Italic = True
Exit For
End If
Next i
ExitHere:
Application.EnableEvents = True
End Sub

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim arrFind
Dim arrReplace
Dim i As Long
If Target.CountLarge > 1 Then Exit Sub
' Modify and expand the arrays as needed
arrFind = Array("WIS", "FLO")
arrReplace = Array("WISCONSIN RAPIDS", "FLORIDA ANGELS")
Application.EnableEvents = False
On Error GoTo ExitHere
For i = 0 To UBound(arrFind)
If Target.Value = arrFind(i) Then
Target.Value = arrReplace(i)
Target.Font.Italic = False
Exit For
End If
Next i
ExitHere:
Application.EnableEvents = True
End Sub

@Ryan_Holtz 

Your new code is also a Worksheet_Change event procedure. I thought that you agreed with me that it would be better to use an ordinary macro...

@Ryan_Holtz 

If you want to combine them:

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim arrFind
    Dim arrReplace
    Dim i As Long
    If Target.CountLarge > 1 Then Exit Sub
    ' Modify and expand the arrays as needed
    arrFind = Array("CAL", "ORE")
    arrReplace = Array("CALIFORNIA DREAMING", "OREGON TRAIL")
    Application.EnableEvents = False
    On Error GoTo ExitHere
    For i = 0 To UBound(arrFind)
        If Target.Value = arrFind(i) Then
            Target.Value = arrReplace(i)
            Target.Font.Italic = True
            Exit For
        End If
    Next i
    ' Modify and expand the arrays as needed
    arrFind = Array("WIS", "FLO")
    arrReplace = Array("WISCONSIN RAPIDS", "FLORIDA ANGELS")
    Application.EnableEvents = False
    On Error GoTo ExitHere
    For i = 0 To UBound(arrFind)
        If Target.Value = arrFind(i) Then
            Target.Value = arrReplace(i)
            Target.Font.Italic = False
            Exit For
        End If
    Next i
ExitHere:
    Application.EnableEvents = True
End Sub
1 best response

Accepted Solutions
best response confirmed by Ryan_Holtz (Copper Contributor)
Solution

@Ryan_Holtz 

This doesn't exist in Excel since, unlike Word, text processing is not its primary purpose.

You might use VBA code. In the attached workbook, Sheet1 will replace some abbreviations and italicize the replacement matching the entire cell. Sheet2 will do the same for part of the cell.

You'll have to allow macros.

The code is in the worksheet modules - right-click a sheet tab and select View Code from the context menu to see and edit it.

View solution in original post