VBA hide rows and columns

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,364
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I'm using a form to capture users input on how many rows/columns show be hidden. Actually, the use with enter on the form the number they want to keep.

The first code below I have for hiding rows, but need it to be variable. It works fine, but not for the columns. Versus using the letter, I need to hide columns by number.

My attempt is below at least for the rows.

Code:
Sub HideRowsCols()
    With Sheets("Linest")
        .Rows("24:103").EntireRow.Hidden = True
        .Columns("8:27").Hidden = True
    End With
End Sub

Code:
Sub HideRowsCols()
    Dim x As Long: x = 24
    Dim xx As Long: xx = 103
    With Sheets("Sheet1")
        .Rows(" x " & ":" & " xx ").EntireRow.Hidden = True
        .Columns("8:27").EntireColumn.Hidden = True
    End With
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Try this:
Code:
Sub HideRowsCols()
    a = 2
    b = 7
    c = 2
    d = 5
    
    With Sheets("sheet1")
        .Rows(a & ":" & b).EntireRow.Hidden = True
        .Range(.Cells(1, c), .Cells(1, d)).EntireColumn.Hidden = True
    End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,465
Messages
6,124,975
Members
449,200
Latest member
Jamil ahmed

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