Hi there: I've been looking at some other posts on replacing text entered with values from two arrays. Works when the values exist in the array; however, if the user enters a different value, then I'd like replace it with "". Please see what I have so far below, and let me know if you have any questions. My apologies for any junk code here. Thanks!
VBA Code:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
''''''''''''''''''''''''''''''''''''''''''''
'Force Y/N column to UPPER case
''''''''''''''''''''''''''''''''''''''''''''
If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub
Dim str As String
Dim fromList() As Variant, toList As Variant, i As Long ', item
fromList = Array("Y*", "YES", "y*", "yes", "y", "N*", "NO", "n*", "no", "n") 'text not allowed
toList = Array("Y", "Y", "Y", "Y", "Y", "N", "N", "N", "N", "N") 'text allowed
str = Target.Value
'On Error Resume Next
If Not Intersect(Target, Range("G3:G5000")) Is Nothing Then
Application.EnableEvents = False
'Target = UCase(Target)
' For Each item In fromList 'replace all items in fromList with ""
' str = Replace(str, item, "")
' Next item
With Range("G3", Cells(Rows.Count, "G").End(xlUp))
'str = Replace(str, i, "")
For i = LBound(fromList) To UBound(fromList)
If i <= UBound(fromList) Then str = Replace(str, fromList(i), "")
.Replace _
What:=fromList(i), Replacement:=toList(i), _
MatchCase:=True
Next
End With
Application.EnableEvents = True
End If
On Error GoTo 0
End Sub