Format text - Event

  • Thread starter Thread starter al007
  • Start date Start date
A

al007

Looking for a worksheet event code which would format text entry in
cells as follows:

..HorizontalAlignment = xlJustify
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False

Can anybody help

Thxs
 
Hello al007,

You can create a new Style for the Workbook. Your Style then become
the default for all worksheets, eliminating redundant worksheet even
code.

Sincerely,
Leith Ros
 
I'm already using a style with cells formatted as custom numbers &
can't have both in text.
That's why I was thinking about a worksheet event - can u help pls
thxs
 
you could use the worksheet's CHANGE event. This is fired when teh ENTER key
is pressed. The 'Target' variable is teh cell or cells changed. Since I want
to avoid formatting numbers, I want to test for them, The Target.Range("A1")
ensures that I test the first cell if more than one cell was enterrd.

Paste this code into the worksheet's code page. Tip: a quick way to the code
page is to select it from the pop-up menu that appears when you RIGHT-Click
thesheet tab...

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)

If Not IsNumeric(Target.Range("A1")) Then

With Target

.HorizontalAlignment = xlJustify
.VerticalAlignment = xlBottom
.WrapText = True
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False

End With

End If

End Sub
 

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

Back
Top