Untitled

mail@pastecode.io avatarunknown
plain_text
a month ago
910 B
2
Indexable
Never
Private initialZoom As Integer

Private Function IsMergedCell(ByVal rng As Range) As Boolean
    IsMergedCell = rng.MergeCells
End Function

Private Function IsCellInRange(ByVal rng As Range, ByVal checkRange As Range) As Boolean
    On Error Resume Next
    IsCellInRange = Not Intersect(rng, checkRange) Is Nothing
    On Error GoTo 0
End Function

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error GoTo GaExcel
    Dim xZoom As Integer
    xZoom = 60

    If Target.Validation.Type = xlValidateList Then
        xZoom = 150
    ElseIf IsMergedCell(Target) Or IsCellInRange(Target, Me.UsedRange) Then
        xZoom = 150
    End If
    
GaExcel:
    If initialZoom = 0 Then
        initialZoom = ActiveWindow.Zoom
    End If

    If xZoom = 150 Then
        ActiveWindow.Zoom = xZoom
    Else
        ActiveWindow.Zoom = initialZoom
    End If
End Sub