This is just a guess since I don't know what the actual worksheet looks like:
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Found As Variant, _
ValAddress As String
'branch to Function FindValidationCells to get the address of the block of cells
'with data validation starting at cell Cll
ValAddress = FindValidationCells
If Not Intersect(Target, Range(ValAddress)) Is Nothing Then
Application.EnableEvents = False
Set Found = Range("types").Find(Target.Value)
If Not Found Is Nothing Then
Found.Copy
Target.PasteSpecial _
Paste:=xlPasteFormats
Application.CutCopyMode = False
Set Found = Nothing
Else
With Target.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With 'target cell
End If 'found
End If 'in validated cells
Application.EnableEvents = True
End Sub
This function starts at cell C11 and tests each cell in that row until it gets to a column with no
validation formula. It then goes down the rows of that column until a cell with no validation
formula is found. It returns the address of the block starting with C11 and ending with the
address of that cell.
Function FindValidationCells() As String
Dim TestValidation As Variant, _
ValTest As Boolean
ValTest = True
Set TestValidation = Range("c11")
While ValTest = True
ValTest = False
Set TestValidation = TestValidation.Offset(0, 1)
On Error Resume Next
ValTest = (TestValidation.Validation.Formula1 = "=Types")
Wend
Set TestValidation = TestValidation.Offset(0, -1)
Err.Clear
ValTest = True
While ValTest = True
ValTest = False
TestValidation.Select
Set TestValidation = TestValidation.Offset(1)
On Error Resume Next
ValTest = (TestValidation.Validation.Formula1 = "=Types")
Wend
Err.Clear
Set TestValidation = TestValidation.Offset(-1)
Set TestValidation = Range("C11", TestValidation.Address(0, 0))
FindValidationCells = TestValidation.Address(0, 0)
Set TestValidation = Nothing
End Function
Bookmarks