Created
May 15, 2013 03:36
-
-
Save stevehenderson/5581498 to your computer and use it in GitHub Desktop.
VBA code to handle mouse click events on cell selection inside Excel worksheets THIS NEEDS TO LIVE IN THE WORKSHEET SPACE
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 | |
Public lastSelectedRow As Integer | |
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) | |
If lastSelectedRow = 0 Then | |
lastSelectedRow = 17 | |
End If | |
Dim r As Integer | |
Dim tempRange As Range | |
r = Target.Row | |
If (r >= 17) And (r <= 47) Then | |
Worksheets("MAIN").Range("$B$3") = ActiveSheet.Cells(r, 1) | |
'Call clearSelectedFormats | |
Set tempRange = Worksheets("MAIN").Cells(lastSelectedRow, 1) | |
With tempRange.Interior | |
.Pattern = xlNone | |
.TintAndShade = 0 | |
.PatternTintAndShade = 0 | |
End With | |
Set tempRange = Worksheets("MAIN").Cells(r, 1) | |
With tempRange.Interior | |
.Pattern = xlSolid | |
.PatternColorIndex = xlAutomatic | |
.Color = 13434879 | |
.TintAndShade = 0 | |
.PatternTintAndShade = 0 | |
End With | |
lastSelectedRow = r | |
End If | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment