Vincent88
Active Member
- Joined
- Mar 5, 2021
- Messages
- 382
- Office Version
- 2019
- Platform
- Windows
- Mobile
Hi Guys,
I use this code to make cells change but I feel the Case is too chunky. Can anyone help to make it more neatly. Basically the following conditions trigger the change to happen :
Conditions to trigger the event
firstcell value and secondcell value
Cells values
firstcell value = ("E") or ("N")
secondcell value =("D", "D1", "D2", "D3", "D4", "D5", "G", "K")
and
firstcell value =("N")
secondcell value =("E")
I use this code to make cells change but I feel the Case is too chunky. Can anyone help to make it more neatly. Basically the following conditions trigger the change to happen :
Conditions to trigger the event
firstcell value and secondcell value
Cells values
firstcell value = ("E") or ("N")
secondcell value =("D", "D1", "D2", "D3", "D4", "D5", "G", "K")
and
firstcell value =("N")
secondcell value =("E")
VBA Code:
Sub PairedCell3()
Application.DisplayStatusBar = False
Application.EnableEvents = False
Application.ScreenUpdating = False
Dim C As Range, rng As Range, rng1 As Range
Set rng = Range("C3", Range("AL" & Rows.Count).End(xlUp))
With rng.Borders
.LineStyle = xlContinuous
.Weight = xlThin
End With
'Make Target and Adjacent Cells Change
For Each C In rng
Case "ED", "ED1", "ED2", "ED3", "ED4", "ED5", "EG", "EK", _
"ND", "ND1", "ND2", "ND3", "ND4", "ND5", "NE", "NG", "NK"
With C.Resize(, 2)
.Borders.LineStyle = xlContinuous
.Borders.Weight = xlThick
.Borders.Color = RGB(102, 0, 255)
End With
End Select
Next C
Application.DisplayStatusBar = True
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub