Excel Demonstrate Only Selected Cells With Macro

Show Only The Selected Rows & Columns In Excel 


         Select an area (cell or cells) on the sheet and press the key on the keyboard ,only that field is displayed. 
Cells outside the selection are hidden .
Then,all cells appear in when you pressed key again.



VBA codes that allow us to hide cells:
Dim i&, a&, s&, t&
    If TypeName(Selection) <> "Range" Then Exit Sub
    If Rows(Rows.Count).EntireRow.Hidden Or Columns(Columns.Count).EntireColumn.Hidden Then
        Cells.EntireColumn.Hidden = False
        Cells.EntireRow.Hidden = False
        Exit Sub
    End If
    i = Selection.Rows(1).Row
    a = i + Selection.Rows.Count - 1
    s = Selection.Columns(1).Column
    t = s + Selection.Columns.Count - 1
    Application.ScreenUpdating = False
    On Error Resume Next
    Range(Cells(1, 1), Cells(i - 1, 1)).EntireRow.Hidden = True
    Range(Cells(a + 1, 1), Cells(Rows.Count, 1)).EntireRow.Hidden = True

    Range(Cells(1, 1), Cells(1, s - 1)).EntireColumn.Hidden = True
    Range(Cells(1, t + 1), Cells(1, Columns.Count)).EntireColumn.Hidden = True
    Application.ScreenUpdating = True


No comments:

Post a Comment