Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim oLookUpRange As Range
Dim sText As String
If IsEntryValid(Target) Then
Set oLookUpRange = Sheets("Data").Range("Data_Table")
sText = BuildString(Target, oLookUpRange)
If sText <> vbNullString Then
Call LogEntry(Target, Sheets("CC"), sText)
End If
End If
End Sub
Private Function IsEntryValid(Target As Range) As Boolean
Dim oInputRange As Range
If Target.Cells.Count > 1 Then
With Application
.EnableEvents = False
.Undo
.EnableEvents = True
End With
MsgBox "You can only edit one cell at a time.", vbCritical
Exit Function
End If
Set oInputRange = Sheets("Hunt").Range("Input_Table")
If Union(Target, oInputRange).Address = oInputRange.Address Then
IsEntryValid = True
End If
End Function
Private Function BuildString(Target As Range, oLookUpRange As Range) As String
Dim I As Long
Dim sKey As Variant
Dim sText As String
With Application.WorksheetFunction
For I = 1 To Len(Target)
sKey = IIf(IsNumeric(Mid(Target, I, 1)), Val(Mid(Target, I, 1)), Mid(Target, I, 1))
Randomize
On Error GoTo ErrHandler
sText = sText + Chr(32) & _
.VLookup(sKey, oLookUpRange, .RandBetween(2, oLookUpRange.Columns.Count), False)
BuildString = sText
Next
End With
Exit Function
ErrHandler:
With Application
.EnableEvents = False
.Undo
.EnableEvents = True
End With
MsgBox "Char: '" & sKey & "' not found in the LookUp Table.", vbCritical
BuildString = vbNullString
End Function
Private Sub LogEntry(Target As Range, Sh As Worksheet, Text As String)
Application.EnableEvents = False
With Sh.Cells(Rows.Count, 1).End(xlUp)
.Offset(1) = Text
.Offset(1, 1) = Format(Now, "hh:mm:ss")
.Offset(1, 2) = Target.Address
.Offset(1, 3) = Target
End With
Application.EnableEvents = True
End Sub
Thanks a Lot! for it. But, i shall iterate it, that can we look for something which shall RETRIEVE message box text and then copy in the CC (Col A) [May be using some Hooks].
Right now, the VBA message box is coming just after the CC(Col A).
Anticipatory thanks!
Private Sub Worksheet_Change(ByVal Target As Range)
Dim oLookUpRange As Range
Dim sText As String
If IsEntryValid(Target) Then
Set oLookUpRange = Sheets("Data").Range("Data_Table")
sText = BuildString(Target, oLookUpRange)
If sText <> vbNullString Then
[B][COLOR=Red]MsgBox sText[/COLOR][/B]
Call LogEntry(Target, Sheets("CC"), sText)
End If
End If
End Sub
Yes, i did that earlier as directed for msgbox.
But, we need to capture this sText before the value gets punched in the CC (Col A).
And the major point is we are unable to take reference from the Data sheet, as we do not know, what value shall be taking up next from the data sheet (in case of original file)
Yep, shall be using the original file, and if the add-in can be made compatible with the project.
But we can wait, till i procure the original file from my friend, if it is required for exceution of the code or making some add-in (for which the coding can be seen - wishing to see how we shall be making it possible) for that.
If the original file is not required, then we can further proceed for this.