I think this code implements your suggestion from post 3. Test in
copy of your workbook. To implement ..
1. Right click the
Sheet1 name tab and choose "View Code".
2. Copy and Paste the code below into the main right hand pane that opens at step 1. (You will need to delete any existing Worksheet_Change code currently in that module)
3. Test by entering/deleting/modifying values in column A of Sheet1
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim s As String
Dim vals As Variant, ListOfNames As Variant
If Target.Count = 1 And Target.Column = 1 And Target.Row > 1 Then
Application.EnableEvents = False
ListOfNames = Application.Transpose(Sheets("Sheet2").Range("A2", Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp)).Value)
s = Target.Value
Target.Interior.Color = xlNone
Target.Offset(, 2).Resize(, UBound(ListOfNames)).ClearContents
If Len(s) > 0 Then
If IsError(Application.Match(s, ListOfNames, 0)) Then
vals = Filter(ListOfNames, s, True)
If UBound(vals) = -1 Then
Target.Offset(, 2).Value = "Error"
Target.Interior.Color = vbRed
Else
Target.Offset(, 2).Resize(, UBound(vals) + 1).Value = vals
Target.Interior.Color = 5296274
End If
Else
Target.Offset(, 2).Resize(, UBound(ListOfNames)).ClearContents
End If
Else
Target.Offset(, 2).Resize(, UBound(ListOfNames)).ClearContents
End If
Application.EnableEvents = True
End If
End Sub
If you enter a partially correct name, the matching suggestions will appear beside it in that same row & the target cell will go green.
If a fully correct name is entered (or the cell is cleared) any names to the right will be cleared and any colour removed.
If no partial match is found then the target cell will go red and "Error" will appear beside the value in that row.
Here is a screen shot where a partially correct name has been entered. the options containing that text are shown in columns C:E in this case.
Book1 |
---|
|
---|
| A | B | C | D | E | F |
---|
1 | Name | Comments | Suggestions | | | |
---|
2 | | | | | | |
---|
3 | Tom | | Tom B | Tom M | John Tom | |
---|
4 | | | | | | |
---|
|
---|