0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

focusCell in xlcel2016

Last updated at Posted at 2025-06-15

Excel 2016에서 Excel 365의 '포커스 셀(행·열 강조)' 기능 구현하기 (VBA + xlam Add-In)

✅ 개요

엑셀 365에는 셀을 선택했을 때 해당 셀의 행과 열이 은은하게 강조되는 '포커스 셀(Focus Shell)' 기능이 내장되어 있습니다.
하지만 엑셀 2016에는 이 기능이 없습니다.

본 글에서는 VBA를 사용해 엑셀 2016에서도 비슷한 효과를 구현하고, 이를 .xlam Add-In으로 저장하여 전역 적용하는 방법을 소개합니다.


🎯 목표 기능 요약

  • 셀 선택 시 해당 행과 열을 은은한 연두색으로 강조
  • 이전 강조는 자동으로 해제
  • 기존 서식(조건부 서식 등) 훼손 없이 작동
  • 성능 저하 없이 화면에 보이는 범위만 처리
  • .xlam으로 저장해 모든 Excel에서 자동 적용

🧩 구현 코드

🔹 1. ThisWorkbook에 넣을 코드 (전역 이벤트)

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    HighlightRowColumn Sh, Target
End Sub

### 🔹 2. `module`에 넣을 코드
```vba
Option Explicit

' 전역 변수
Public LastHighlightedCells As Collection
Public OriginalColorDict   As Object

Public Sub HighlightRowColumn(ByVal ws As Worksheet, ByVal Target As Range)
    Dim visibleRow     As Range
    Dim visibleCol     As Range
    Dim highlightRange As Range
    Dim cell           As Range
    Dim baseColor      As Long
    
    On Error GoTo CleanExit
    Application.EnableEvents = False
    Application.ScreenUpdating = False
    
    ' ───────────────────────────────────────────────────────────
    ' 1) 이전 강조 제거 & 원색 복원
    If Not LastHighlightedCells Is Nothing Then
        For Each cell In LastHighlightedCells
            With cell.Interior
                If OriginalColorDict.Exists(cell.Address) Then
                    .Color = OriginalColorDict(cell.Address)
                Else
                    .ColorIndex = xlColorIndexNone
                End If
                .TintAndShade = 0
            End With
        Next
    End If
    
    ' ───────────────────────────────────────────────────────────
    ' 2) 새 컬렉션·딕셔너리 초기화
    Set LastHighlightedCells = New Collection
    Set OriginalColorDict   = CreateObject("Scripting.Dictionary")
    
    ' ───────────────────────────────────────────────────────────
    ' 3) 화면에 보이는 해당 행·열만 계산
    Set visibleRow = Intersect(ws.Rows(Target.Row),    ActiveWindow.VisibleRange)
    Set visibleCol = Intersect(ws.Columns(Target.Column), ActiveWindow.VisibleRange)
    
    If Not visibleRow Is Nothing Then
        Set highlightRange = visibleRow
    End If
    If Not visibleCol Is Nothing Then
        If highlightRange Is Nothing Then
            Set highlightRange = visibleCol
        Else
            Set highlightRange = Union(highlightRange, visibleCol)
        End If
    End If
    
    ' ───────────────────────────────────────────────────────────
    ' 4) 강조 적용
    If Not highlightRange Is Nothing Then
        baseColor = RGB(204, 255, 204)  ' 연한 초록
        
        For Each cell In highlightRange.Cells
            With cell.Interior
                ' (1) 원래 색 백업
                If .ColorIndex <> xlColorIndexNone Then
                    OriginalColorDict(cell.Address) = .Color
                End If
            End With
            
            If cell.Address = Target.Address Then
                ' (2) 선택된 셀만 투명 처리
                With cell.Interior
                    .ColorIndex    = xlColorIndexNone
                    .TintAndShade  = 0
                End With
            Else
                ' (3) 나머지 셀은 연한 초록 강조
                With cell.Interior
                    .Color        = baseColor
                    .TintAndShade = 0.6
                End With
            End If
            
            ' (4) 나중에 해제할 때를 위해 저장
            LastHighlightedCells.Add cell
        Next
    End If

CleanExit:
    Application.EnableEvents   = True
    Application.ScreenUpdating = True
End Sub
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?