Reverse function in cells


Posted by Nick on October 28, 2000 5:33 AM

I have made a macro function and I am trying to use this function on cells in a spreadsheet but I cannot figure it out. My code for the reverse function is :

-Start of code-
Function Reverse (text as string) as string
For N = len(text) to 1 step - 1
reverse = reverse & mid(text,n,1)
Next N
End function
-End of code-

Run it in immeadiate mode to test if you wish.

So far I have the following but something is missing:

-Strat of code-
Function rangereverse(sheete, cellz)
Worksheets(sheete).Activate
Worksheets(sheete).Range(cellz).Function = "reverse"
End Function
-End of code-

I need to use a the following command:

call rangereverse ("Sheet1", "A1:C3")

or any cell range.

Can you help me get this to work using another sub procedure to reverse cells, with any range of cells?



Posted by Ivan Moala on October 28, 2000 6:12 AM

Nick your reverse function works
The other one will not work as a function
you need this as a sub..........eg

Sub Reverse_SheetRg(Sheete As String, cellz As String)
Dim Sh
Dim oCell

On Error GoTo Err
Set Sh = Worksheets(Sheete).Range(cellz)
For Each oCell In Sh
oCell.Value = Reverse(oCell.text)
Next

Exit Sub
Err:
MsgBox Err.Number & " : " & Err.Description
End Sub


Use this routine to call the Sub

Sub TestCall()
Call Reverse_SheetRg("Sheet2", "B5:B9")
End Sub


HTH

Ivan