Code to change text direction

  • Thread starter Thread starter Cranky
  • Start date Start date
C

Cranky

Hi

I'm looking for code to change the direction of text in a cell from
horizontal to vertical at the click of a user button. Please could
anyone advise on how to do it?

Thanks in advance

Steve
 
Hi

Here's code to get you started, ik works on cell A1.

Sub reverseletters()

Dim i As Integer
Dim sTemp As String

For i = Len(Range("A1").Value) To 1 Step -1
sTemp = sTemp & Mid(Range("A1").Value, i, 1)
Next

Range("A1").Value = sTemp

End Sub
 
Wigi

Thanks for replying so quickly, and it takes care of something else I
was looking at. What I meant to say was the orientation of the text
from Hortizontal was to change to vertical at the click of the button.

Sorry for not explaining properly

Steve
 
In xl2003, you can add a formatting button to your favorite toolbar.

Tools|Customize|commands tab|Format category
scroll down until you see icons for the rotate text up and rotate text down and
drag to your favorite toolbar.

You may want to create a new toolbar with all your favorite formatting icons on
it, too.

And if you wanted to reverse the text in a cell, here's another option if you're
using xl2k or higher (strreverse was added in xl2k):

Option Explicit
Function ReverseTheText(myStr As String) As String
ReverseTheText = StrReverse(myStr)
End Function

You use it like a builtin function:
=reversethetext(a1)
 
Try the macro recorder whilst doing the steps.

This is my result.

Sub Macro4()
'
' Macro4 Macro
' Macro recorded 05/08/2008 by Gord Dibben
'

'
Range("F5").Select
With Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 90
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
End Sub

Scrub out the lines you probably don't need.

Sub Macro4()
With Selection
.Orientation = 90
End With
End Sub


Gord Dibben MS Excel MVP
 
ps. If you really want to create your own button (like on a worksheet), record
the code when you format the cell manually and you should be pretty much done.

Post back if you have trouble.
 
Apologies Dave and Gord, I haven't been able to reply to your posts
until tonight. Thanks you for your replies; I've got it doing exactly
what I wanted it to, now. Thanks very much.

Best,

Steve
 
Back
Top