Written by Allen Wyatt (last updated February 25, 2023)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021
Conrad would like to mimic the "small caps" capability of Word within Excel. The only way he can think to do this is to develop a macro that steps through every character in a cell. If the character is lowercase and 11 pt, then the macro should change the character to uppercase 9 pt. If the character is uppercase (or not a letter), then it should not be affected. Problem is, Conrad doesn't know how to affect the formatting of individual characters in the cell in the manner described.
When using a macro to affect only certain characters within the cell, it is good to remember that each cell has its own Characters collection that can be accessed and modified. Each element in the collection represents, as you might expect, a single character in the cell.
This allows us to put together a macro that examines what is currently in the cell, and if the character is currently lowercase, convert just that character to uppercase and reduce that character's font size.
Sub SmallCaps() Dim rCell As Range Dim sWords As String Dim sCharacter As String Dim x As Long 'go through each cell in selection For Each rCell In Selection 'Don't want to work on formulas If Not rCell.HasFormula Then sWords = rCell.Value 'Get the cell contents For x = 1 To Len(sWords) 'Act on each letter sCharacter = Mid(sWords, x, 1) If sCharacter >= "a" And sCharacter <= "z" Then 'sCharacter is a lowercase letter With rCell.Characters(Start:=x, Length:=1) 'Decrease the font size by 2 .Font.Size = .Font.Size - 2 'Make character uppercase .Text = UCase(sCharacter) End With End If Next End If Next End Sub
This macro does its work on whatever cells are selected when it is run. It checks to make sure the cell doesn't contain a formula (formulas are skipped), and then it makes any modification to lowercase characters in the cell.
There are drawbacks to using a macro such as this, and you should be aware of them. The biggest drawback is that it actually modifies what is in the cells. When it is done, the cells will contain all uppercase text, even though the formatting may make it look like small caps. This means that you may have problems when you later run the macro a second time, and Excel's proofing tools (such as the spell checker) won't work on words that are all uppercase. (Excel can, however, be configured to still spell check such words.)
Because of the drawbacks, you may want to take an entirely different approach—change the font you use for the cells in which you want small caps. If you search the web for a "small caps fonts" (without the quote marks) you should be able to find many candidates, and a good number of them are available for free. Here is one site that may have something you like:
https://www.fontsquirrel.com/fonts/list/tag/small%20caps
Just download the font you want (from this or any other reputable source) and install it on your system. When you restart Excel, the font should be available for formatting cells. Cells formatted to use such a font would show text as small caps, even though the actual cell contents are a mixture of upper- and lowercase.
One thing to be aware of if you go the route of using a small-caps font: If you share the workbook with someone who doesn't have that font installed on their system, there may be problems. The workbook won't be "hurt" in any way, but the information in the workbook will probably not display correctly as Excel will substitute a default font in place of the one you chose.
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (653) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021.
Solve Real Business Problems Master business modeling and analysis techniques with Excel and transform data into bottom-line results. This hands-on, scenario-focused guide shows you how to use the latest Excel tools to integrate data from multiple tables. Check out Microsoft Excel 2013 Data Analysis and Business Modeling today!
If you get an error when you try to use one of your custom views, it could be due to the protection you have applied to ...
Discover MoreCurrency is formatted differently in different corners of the world. Most formatting uses periods and commas to indicate ...
Discover MoreWhen you format a date in a specific manner, you may be surprised to see that the format changes when you open the ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2023-03-11 15:13:36
J. Woolley
The following macros in My Excel Toolbox have been updated to support Undo (Ctrl+Z) similar to the TextSmallCaps macro described in my previous comment below: TextLowerCase, TextUpperCase, TextProperCase, TextTitleCase, TextToNumber, TextFromNumber, TextTrim, and TextClean.
See https://sites.google.com/view/MyExcelToolbox/
2023-03-06 17:54:35
J. Woolley
Inspired by this Tip, the TextSmallCaps macro was added to My Excel Toolbox. Unlike the Tip's macro, TextSmallCaps supports Undo (Ctrl+Z). Here is an abbreviated version.
Public Sub TextSmallCaps()
Const myName As String = "TextSmallCaps"
TextSmallCaps_Undo False
Application.OnUndo ("Undo " & myName), _
(ThisWorkbook.Name & "!" & myName & "_Undo")
End Sub
Private Sub TextSmallCaps_Undo(Optional Undo As Boolean = True)
Static rText As Range, sSave() As String
Dim rCell As Range, sText As String, sChar As String
Dim nSave As Long, n As Integer
Const nSub As Integer = 2
If Not Undo Then
Set rText = Selection.SpecialCells(xlCellTypeConstants, xlTextValues)
Set rText = Intersect(Selection, rText) 'in case single cell selected
If rText Is Nothing Then Exit Sub
ReDim sSave(1 To rText.Cells.Count)
End If
rText.Select
nSave = 0 'unnecessary
For Each rCell In rText
With rCell
nSave = nSave + 1
If Undo Then
sText = sSave(nSave)
Else
sText = .Value
sSave(nSave) = sText
End If
If Not IsNumeric(sText) Then
For n = 1 To Len(sText)
sChar = Mid(sText, n, 1)
If sChar >= "a" And sChar <= "z" Then
With .Characters(n, 1)
If Undo Then
.Text = sChar
.Font.Size = .Font.Size + nSub
Else
.Text = UCase(sChar)
.Font.Size = .Font.Size - nSub
End If
End With
End If
Next n
End If
End With
Next rCell
End Sub
See https://sites.google.com/view/MyExcelToolbox/
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments