Try the code in the Workbook module then in the Sheet Selection Change event
Option Explicit
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
Dim RowNo As Long, ColNo As Long
Dim LastRow As Long
Dim ColourIndex As Long
Dim isect As Range
If Sh.Name = "Sheet3" Then Exit Sub
If Target.Cells.Count > 1 Then Exit Sub
LastRow = Range("A" & Rows.Count).End(xlUp).Row
Set isect = Intersect(Target, Range("B2:B" & LastRow))
If Not isect Is Nothing Then
RowNo = Range("F:F").Find(Target.Offset(0, -1)).Row
ColNo = Range("1:1").Find(Target.Offset(0, 1)).Column
Cells(RowNo, ColNo) = Target
Cells(RowNo, ColNo).Interior.ColorIndex = Range("O:O").Find(Target).Interior.ColorIndex
End If
End Sub
This should do as you need in all the sheets in your workbook, provided they all have exactly the same layout.
I have added this line
If Sh.Name = "Sheet3" Then Exit Sub
This means the code will fire in all sheets except "Sheet3", take this line out if it is not required.
I put it in only as an example to illustrate that you can use that feature to do different things with different groups of sheets. For instance you could use a Select Case sh.Name statement to apply code to different groups of sheets.
If each sheet is different and needs individually coded then use the Worksheet Modules for each sheet.
If groups or all sheets use the same code then use the Workbook Modules.
There is no need to change the variable names.
Hope this helps
Bookmarks