Excel VBA to hide a certain number of hide rows on one sheet, columns on another, based on number

gtirrell

New Member
Joined
Jun 16, 2022
Messages
13
Office Version
  1. 365
Platform
  1. Windows
I want to hide a certain number of rows on one sheet, and columns in another, based on the number in a certain cell. I have 30 rows labeled as 1-30 in A11:A40 on Sheet1 and 30 columns on Sheet2 labeled as 1-30 in F9:AI9. When you enter a number in a certain cell (e.g. "7" in cell C8), I want it to hide rows 8-30 on Sheet1 and columns 8-30 on Sheet2.

This works for Sheet1, but I don't know how to reference another sheet or have it simultaneously apply to columns:

Sub Hide_Rows_Columns()

Dim c As Range
For Each c In Range("A11:A40").Cells
If c.Value > Range("C8") Then
c.EntireRow.Hidden = True

End If
Next c

End Sub

Also, can this work just by entering the value in C8 and not having to press run on the macro?
 
You're welcome & thanks for the feedback.
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

Forum statistics

Threads
1,214,593
Messages
6,120,435
Members
448,962
Latest member
Fenes

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