View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Patrick Molloy[_2_] Patrick Molloy[_2_] is offline
external usenet poster
 
Posts: 1,298
Default Format text - Event

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


"al007" wrote:

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