Hide Rows/Hide Columns Based on Value in Cell

brickwall823

New Member
Joined
Jul 24, 2015
Messages
1
Hello!

I am just getting started with VBA, and am trying to figure out two separate but related questions.

I was hoping to set up a macro that would let me

1) Show columns where cell in row 2 equals values in 1 of 3 cells on a separate worksheet. So if the value in row 2 of current worksheet = value of cell 1 or cell 2, or cell 3 on a different worksheet, then show the column, otherwise hide it. The values of cell 1, cell 2 and cell 3 are dynamic and will change.

on the same worksheet

2) Hide rows where cell in column I, equal "Inside", "Outside", "In-and-Out" and show the rest

Thank you so much for you help!
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
this may get you started in the right direction

Rich (BB code):
sub HidingMacro

if cells(2,1) <> Workbooks("OtherWorkbookName").Sheets("WhateverSheet").range(A1:A3) then
cells(2,1).columns.delete
end if

'part 2
for x = 1 to cells(rows.count,9).end(xlup).row

if cells(x,9) = "Inside" or "Outside" or "In-and-Out" then
cells(x,9).entirecolumn.hide
end if 

next

This code is pretty sloppy and it's 3AM where I am so there are probably a number of errors with this, but hopefully it at least gets you thinking in the right direction.

-Ray
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,491
Messages
6,125,111
Members
449,205
Latest member
ralemanygarcia

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