'Can Excel Worksheet Events be made to work like that of Google Translate?
I am writing a program in the Worksheet_SelectionChange
event to better understand the worksheet events, how it is fired and such.
My program takes the string in "A1" and gives the reversed string in "B1".
It is not as elegant as the Google Translate. In Google Translate with every keystroke, the translate function is up and running, while in my case I need to select a different cell then select "A1" again, for the event to fire and give the output.
Are there ways to make the events better or, create our own events, or use a combination of available events.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim MyRange As Range
Set MyRange = Sheet1.Range("A1")
If Not Intersect(Target, MyRange) Is Nothing Then
If Target.Cells.Count > 1 Then
Exit Sub
Else
Target.Offset(0, 1).value = ""
Target.Offset(0, 1).value = ReverseWord(Target.value)
End If
End If
End Sub
Private Function ReverseWord(val As String)
Dim newstring As String
Dim pos As String
For j = Len(val) To 1 Step -1
pos = Mid(val, j, 1)
newstring = newstring & pos
Next
ReverseWord = newstring
End Function
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|