Created
October 15, 2016 15:44
-
-
Save danwagnerco/8e74dfd18c771d6f526cfbd90cd2f05e to your computer and use it in GitHub Desktop.
This macro will highlight cells in column G based on the selection in column A
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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