Hi, I have problems with some part of my macro. I just make macro which hide all rows and columns without selected area. Let's say that in selected area there are some hidden rows and columns. I know how to expose them (bolded part of code). When I start my macro again, almost everything is the same, but rows and columns in selected area are now unhidden (initially they wre hidden). How to hide them again in VBA code?
Sub HideRowsAndColumns() Dim row1 As Long, row2 As Long Dim col1 As Long, col2 As Long If TypeName(Selection) <> "Range" Then Exit Sub [B]Selection.EntireRow.Hidden = False[/B] [B]Selection.EntireColumn.Hidden = False[/B] 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 row1 = Selection.Rows(1).Row row2 = row1 + Selection.Rows.Count - 1 col1 = Selection.Columns(1).Column col2 = col1 + Selection.Columns.Count - 1 Application.ScreenUpdating = False On Error Resume Next Range(Cells(1, 1), Cells(row1 - 1, 1)).EntireRow.Hidden = True Range(Cells(row2 + 1, 1), Cells(Rows.Count, 1)).EntireRow.Hidden = True Range(Cells(1, 1), Cells(1, col1 - 1)).EntireColumn.Hidden = True Range(Cells(1, col2 + 1), Cells(1, Columns.Count)).EntireColumn.Hidden = True End Sub