Seçili Hücrenin En Üstündeki Ve En Solundaki Hücreyi Renklendir - Microsoft Excel


Ö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.

Kod


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

Etiketler
microsoft excel microsoft excel vba microsoft excel vba renklendirme işlemleri