Hide rows based on prior setup sheet

edjohn20

New Member
Joined
Mar 5, 2024
Messages
34
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I know there is VBA code to do this. I don't know VBA well enough to write it. However I know exactly what I want to do.

I have a worksheet 1 titled "Setup" and worksheet 2 titled "MMS PaaS Pricing 2024"

I have configurable in Setup B4 to B11. This field will be either YES or NO (chosen from drop down)

core
IF b4=NO the Hide "MMS PaaS Pricing 2024" rows 9-15
cm
IF b5=NO the Hide "MMS PaaS Pricing 2024" rows 16-21
sc
IF b6=NO the Hide "MMS PaaS Pricing 2024" rows 22-30
acm
IF b7=NO the Hide "MMS PaaS Pricing 2024" rows 31-38
ssm
IF b8=NO the Hide "MMS PaaS Pricing 2024" rows 39-46
lca
IF b9=NO the Hide "MMS PaaS Pricing 2024" rows 47-55
web
IF b10=NO the Hide "MMS PaaS Pricing 2024" rows 56-63
movr
IF b11=NO the Hide "MMS PaaS Pricing 2024" rows 64-69

There are also formulas and values within the cells to be hidden that need to be suppressed as well. Meaning if SC section is NO then the fees and values do not get included.
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
try this.

VBA Code:
Sub Hide()

Dim rs As Worksheet
Set rs = Worksheet("MMS PaaS Pricing 2024")


rs.Rows("6:69").Hidden = False

If [B4] = "NO" Then rs.Rows("9:15").Hidden = True
If [B5] = "NO" Then rs.Rows("16:21").Hidden = True

'......add the rest as needed
End Sub

hth,
Ross
 
Upvote 0
Thank you so much. I have one question regarding where this code should be applied. Should it be module 1 or attached to certain sheet? Also what will invoke the changes? Will it be live to changes in Setup b column or will I need to run macro?
 
Upvote 0
it can reside in module1.

for now just add a shape to your sheet and assign the macro the the shape.
once you have it working then you can assign it the cells B4:B11) that, when changed, would fire off the macro
 
Upvote 0
it can reside in module1.

for now just add a shape to your sheet and assign the macro the the shape.
once you have it working then you can assign it the cells B4:B11) that, when changed, would fire off the macro
Ok, it is giving me a compile error: sub or function not defined.

Is it due to the () at the top?
 
Upvote 0
I will see if I can get some screen shots to show what I am seeing. I certainly appreciate your help
 
Upvote 0
So maybe I changed something. I don't know. Does not look like I did. I am not sure if it is looking to worksheet "Setup" to determine b values but here is current code loaded in module one:

Sub Hide()

Dim rs As Worksheet
Set rs = Worksheet("MMS PaaS Pricing 2024")


rs.Rows("6:69").Hidden = False

If [B4] = "NO" Then rs.Rows("9:15").Hidden = True
If [B5] = "NO" Then rs.Rows("16:21").Hidden = True
If [B6] = "NO" Then rs.Rows("22:30").Hidden = True
If [B7] = "NO" Then rs.Rows("31:38").Hidden = True
If [B8] = "NO" Then rs.Rows("39:46").Hidden = True
If [B9] = "NO" Then rs.Rows("47:55").Hidden = True
If [B10] = "NO" Then rs.Rows("56:63").Hidden = True
If [B11] = "NO" Then rs.Rows("64:69").Hidden = True


'......add the rest as needed
End Sub
 
Upvote 0
oops,

change
Set rs = Worksheet("MMS PaaS Pricing 2024")
to
Set rs = Worksheets("MMS PaaS Pricing 2024")
 
Upvote 0
oops,

change
Set rs = Worksheet("MMS PaaS Pricing 2024")
to
Set rs = Worksheets("MMS PaaS Pricing 2024")
Oh, awesome. That works. Now to assign to button. Would it be form button or active X. I hate that I am asking all these questions, but I certainly appreciate the assistance.
 
Upvote 0
just go to insert menu and select shape, pick any shape you want, right click and assign macro to it.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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