Hide Columns & Rows VBA - Thank You In Advance

jbuffnola

New Member
Joined
Apr 6, 2011
Messages
2
I am somewhat a novice with VBA, in other words, I am still learning. I am trying to write a vba macro that would hide columns based on what is presented in another table. This will allow me to update the table and not have to worry about updating the macro on a continuing basis.

For example.

Columns
A1: Football
B1: Basketball
C1: Baseball
D1: Hockey - HIDE
E1: Soccer - HIDE

Table Hide:
Hockey
Soccer


OR

Would you suggest creating an if statement that would assign anything in the table to be equal to = X.
Therefore, writing the code to hide columns in A1:E1 = X.

Thank you in advance,
~ Jason
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hi there,

Welcome to the board.

Try:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Range("A1:A10")) Is Nothing Then
        If Target.Count > 1 Then Exit Sub
        If Target.Value = "" Then Exit Sub
        lRow = Sheets("Sheet2").Range("A1").End(xlDown).Row
        Set wFind = Sheets("Sheet2").Range("A2:A" & lRow).Find(Target.Value)
        If Not wFind Is Nothing Then wFind.EntireRow.Hidden = True
    End If
End Sub

If anything is typed into A1:A10 on sheet1 then it will find it in Sheet2 and hide it, if it can't find it then nothing will happen.

Change ranges to suit.
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,181
Members
452,893
Latest member
denay

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