Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » Excel

Code to change text direction

 
Jump to:  
 
Cranky
PostPosted: Tue Aug 05, 2008 1:56 pm    Post subject: Code to change text direction
       
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
 

 
Wigi
PostPosted: Tue Aug 05, 2008 1:56 pm    Post subject: RE: Code to change text direction
       
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
LINK = Excel/VBA, soccer and music


"Cranky" wrote:

Quote:
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
 

 
Dave Peterson
PostPosted: Tue Aug 05, 2008 1:56 pm    Post subject: Re: Code to change text direction
       
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)




Cranky wrote:
Quote:

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

--

Dave Peterson
 

 
Gord Dibben
PostPosted: Tue Aug 05, 2008 1:56 pm    Post subject: Re: Code to change text direction
       
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

On Tue, 5 Aug 2008 07:40:15 -0700 (PDT), Cranky
<crankylemming@googlemail.com> wrote:

Quote:
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



On Aug 5, 3:11 pm, Wigi <W...@discussions.microsoft.com> wrote:
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
 

 
Dave Peterson
PostPosted: Tue Aug 05, 2008 1:56 pm    Post subject: Re: Code to change text direction
       
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.

Dave Peterson wrote:
Quote:

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)

Cranky wrote:

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

--

Dave Peterson

--

Dave Peterson
 

 
Cranky
PostPosted: Tue Aug 05, 2008 2:40 pm    Post subject: Re: Code to change text direction
       
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



On Aug 5, 3:11 pm, Wigi <W...@discussions.microsoft.com> wrote:
Quote:
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
 

 
Cranky
PostPosted: Thu Aug 07, 2008 9:27 pm    Post subject: Re: Code to change text direction
       
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
 

Page 1 of 1 .:.

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

sypialnia Biuro Nieruchomoƛci KrakĂłw pokazy pirotechniczne dziaƂki budowlane na sprzedaĆŒ Fotka