This macro will highlight cells in column G based on the selection in column A
Option Explicit | |
Private Sub Worksheet_SelectionChange(ByVal Target As Range) | |
Dim wksLookups As Worksheet | |
Dim lngFirstRow As Long, lngLastRow As Long | |
'Get the Worksheet so we can confidently identify | |
'the Range that we'll be highlighting (if need be) | |
Set wksLookups = Target.Parent | |
'Clear the background color in column G (7) | |
wksLookups.Columns(7).Interior.ColorIndex = xlNone | |
'First, we need to check that the selection | |
'occurred in column A (1) AND was in a row after | |
'row 1 | |
If Target.Column = 1 And Target.Row > 1 Then | |
'Find the first and last rows of the selected | |
'range in column A | |
lngFirstRow = Target.Row | |
lngLastRow = Target.Rows.Count + (Target.Row - 1) | |
'Highlight the corresponding cell(s) in column G (7) | |
With wksLookups | |
.Range(.Cells(lngFirstRow, 7), _ | |
.Cells(lngLastRow, 7)).Interior.Color = RGB(255, 255, 0) | |
End With | |
End If | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment