Formula for formatting font/style

S

Sarah C

Hello!

I am creating a spreadsheet where, in a certian column, each entry starts
with a bold capital letter that codes for something, followed by a text
description. I am hoping a formula or setting exists so that I can type my
information in and automatically capitalize and bold the first letter, then
keep the rest unbolded. Is this possible, and if so, what's the formula?
Thank you!
 
T

Tom Hutchins

As Peo wrote, you can do it with VBA.

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Columns("A:A")) Is Nothing Then Exit Sub
Dim x As Integer
x = Len(Target.FormulaR1C1)
If x > 0 Then
Target.Font.Bold = False
With Target.Characters(Start:=1, Length:=1).Font
.FontStyle = "Bold"
End With
End If
If x > 0 Then
With Target.Characters(Start:=2, Length:=x - 1).Font
.FontStyle = "Regular"
End With
End If
End Sub

To use this event macro, right-click on the tab of the sheet where you want
this to happen. From the menu that appears, select View Code (this opens the
Visual Basic Editor). Paste the code in the window that opens. Change "A:A"
in the code to whatever the correct column should be. Save the workbook.
Close the editor and return to regular Excel by pressing Alt-Q.

If you are new to macros), this link to Jon Peltier's site may be helpful:
http://peltiertech.com/WordPress/2008/03/09/how-to-use-someone-elses-macro/

Hope this helps,

Hutch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top