Macro to hide hide rows/cols below/right of current selected cell

F_Rowan

New Member
Joined
Nov 6, 2015
Messages
3
Hi Experts -
I am seeking VBA code that will hide all rows below and all columns right of the currently selected cell of the current active sheet. i.e.; If the current selected cell is F23, the macro should hide all rows below row 23 and all columns to the right of column F.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Maybe:
Code:
Sub HideRowsCols()
    Rows(Selection.Row & ":" & 1048576).EntireRow.Hidden = True
    Range(Cells(Selection.Column, Selection.Row), Cells(1048576, 16384)).Columns.Hidden = True
End Sub
 
Upvote 0
Give this a try...
Code:
Sub HideRowsAndColumns()
  Range(Selection.Offset(, 1), Cells(1, Columns.Count)).Columns.Hidden = True
  Range(Selection.Offset(1), Cells(Rows.Count, "A")).Rows.Hidden = True
End Sub
 
Upvote 0
This version uses a forms control command button (Button 1 - change name to suit) located in cell A1 and initially captioned "Hide" (changes to "Unhide" to allow subsequent recovery of all columns and rows).
Code:
Sub Button1_Click()
Dim T As Range
Set T = ActiveCell
Application.ScreenUpdating = False
ActiveSheet.Shapes("Button 1").Select
Select Case Selection.Characters.Text
    Case "Hide"
        Rows(T.Row + 1 & ":" & Rows.Count).Hidden = True
        Range(Cells(1, T.Column + 1), Cells(1, Columns.Count)).EntireColumn.Hidden = True
        Selection.Characters.Text = "Unhide"
        ActiveWindow.RangeSelection.Select
    Case "Unhide"
        Cells.EntireRow.Hidden = False
        Cells.EntireColumn.Hidden = False
        Selection.Characters.Text = "Hide"
        ActiveWindow.RangeSelection.Select
End Select
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thank you each for your quick and clear replies. I ended up using Rick Rothstein's code for my needs.
 
Upvote 0

Forum statistics

Threads
1,221,418
Messages
6,159,790
Members
451,589
Latest member
Harold14

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top