PDA

View Full Version : [SOLVED:] Help in Alteration of Code - Urgent



Khanonline
04-21-2015, 03:22 AM
Hello All,

I need to work on reverse of Text and I am having caption in the Table like in below table.


This is Caption

12

12



.tset si sihT

12

12



This is test.

12

12



This is test.

12

12



This is test.

12

12



This is test.

12

12




I want if I select all the Captions in Table it should apply the macro on it. Can somebody help me to alter the code or do this for me?
Result f After applying Macro:


noitpaC si sihT

12

12



.tset si sihT

12

12



.tset si sihT

12

12



.tset si sihT

12

12



.tset si sihT

12

12



.tset si sihT

12

12




The Macro is:
Dim oRng As Range
Dim sRevText As String
Dim i As Long
sRevText = ""
Set oRng = Selection.Range
For i = oRng.Characters.Count To 1 Step -1
sRevText = sRevText & oRng.Characters(i)
Next i
oRng.Text = sRevText

Please make the alteration or assist me in doing it with efficient manner.

Thanks a bunch.
Regards
Khanonline

Khanonline
04-22-2015, 12:12 AM
Hello all,

If above mentioned explanation doesn't make sense. Then can anybody help me with this code to alter for selected captions (in one column) of Table of Ms Word?

Code:
Dim oRng As Range
Dim sRevText As String
Dim i As Long
sRevText = ""
Set oRng = Selection.Range
For i = oRng.Characters.Count To 1 Step -1
sRevText = sRevText & oRng.Characters(i)
Next i
oRng.Text = sRevText


Thanks in advance.
Regard
Khanonline

mancubus
04-22-2015, 01:54 AM
please use code tags when posting your code to the thread. When you click # button in Quick Reply code tags (without spaces) will be inserted.

[ CODE ]paste your code between these tags[ /CODE ]

VBA has StrReverse function. you dont need any code to reverse a string.

select cells in a table before running this macro


Sub ReverseTextInSelectedTableCells()

Dim TableCell As Cell

For Each TableCell In Selection.Cells
TableCell.Range.Text = StrReverse(TableCell.Range.Text)
Next TableCell

End Sub

Khanonline
04-22-2015, 10:59 AM
Thanks Man.... You made my life easier.......... :)