jeudi 18 novembre 2021

Check if cell input matches another cell input from list

I'm new to coding with excel vba, but i have an excel map with a list of superiors and a list of potential successor. Now i got the task to create an excel map where you can put in the position of a superior into an Input Box and it should automatically show you the successors that fit based on their current position e.g. only heads of departments can become CEO.

For Each Column1 In Range("D3:D6").Columns
For Each cell1 In Column1.Cells
For Each Column2 In Range("N3:N6").Columns
For Each cell2 In Column2.Cells

If cell1.Value = "MM" And cell2.Value = "AL" Or cell2.Value = "MM Asp." Or cell2.Value = "Tagesvertretung" Or cell2.Value = "MM-Stv." Or cell2.Value = "VM" Or cell2.Value = "FM" Then
cell2.Interior.ColorIndex = 10
ElseIf cell1.Value = "FM" And cell2.Value = "AL" Or cell2.Value = "MM" Then
cell2.Interior.ColorIndex = 10
ElseIf cell1.Value = "VM" And cell2.Value = "MM" Then
cell2.Interior.ColorIndex = 1
ElseIf cell1.Value = "VL" And cell2.Value = "VM" Or cell2.Value = "FM" Then
cell2.Interior.ColorIndex = 10
ElseIf cell1.Value = "VD" And cell2.Value = "VM" Or cell2.Value = "FM" Or cell2.Value = "VL" Then
cell2.Interior.ColorIndex = 10
ElseIf cell1.Value = "MM-Stv." And cell2.Value = "AL" Then
cell2.Interior.ColorIndex = 10
Else
cell2.Interior.ColorIndex = 3
End If

Next
Next
Next
Next

Theoretically it does what i want it to although it either colors the cells wrong or it only changes the colo of the whole range (N3:N6) when i change the last cell (N6)

Thanks in advance for your help

Aucun commentaire:

Enregistrer un commentaire