Örneğin G50 hücresi seçiliyse, G sütununun en üstünde bulunan G1 hücresini ve 50. satırın en solunda bulunan A50 hücresini renklendiren VBA kodudur.
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'---------------------------------------
'Değişkenler
'---------------------------------------
Dim satir As Long
Dim sutun As Long
'---------------------------------------
'Seçili hücrenin en üstündeki hücreyi seç.
'---------------------------------------
Range("A1:IV1").Interior.ColorIndex = xlNone
sutun = Target.Column
Cells(1, sutun).Interior.ColorIndex = 6
'---------------------------------------
'Seçili hücrenin en solundaki hücreyi seç.
'---------------------------------------
Range("A:A").Interior.ColorIndex = xlNone
satir = Target.Row
Range("A" & satir).Interior.ColorIndex = 6
End Sub