Reverse the Contents of a Cell

This function is mostly fun, but you may find it useful—it reverses the contents of a cell. ReverseContents(myCell, IsText)

The arguments are myCell—The specified cell.

IsText—Optional, should the cell value be treated as Text (Default) or a number. Function example:

Function ReverseContents(myCell As Range, Optional IsText As Boolean = True) Dim i As Integer

Dim OrigString As String, NewString As String OrigString = Trim(myCell) 'remove leading and trailing spaces For i = 1 To Len(OrigString)

'by adding the variable NewString to the character, 'instead of adding the character to NewStringthe string is reversed

NewString = Mid(OrigString, i, 1) & NewString Next i

If IsText = False Then

ReverseContents = CLng(NewString)

Else

ReverseContents = NewString End If

End Function

0 0

Post a comment