Code to change text direction

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
 
W

Wigi

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
 
C

Cranky

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
 
D

Dave Peterson

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)
 
G

Gord Dibben

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
 
D

Dave Peterson

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.
 
C

Cranky

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
 

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