VBA Hiding Columns: combining two criteria

kfryar

New Member
Joined
May 5, 2015
Messages
3
Hi all!

I have a macro that hides columns depending on what is in cell "A3", now i need to add another criteria depending on cell "D1" - have built both macros but running the second macro will open some columns that should be closed by the first macro... SO... I need to combine these two macros so columns meeting either criteria will remain closed.

MACRO 1:


Sub hide_columns1()
Dim lngCol As Long, c As Range​

lngCol = Cells(11, Columns.Count).End(xlToLeft).Column

Application.ScreenUpdating = False

Cells.Columns.Hidden = False

For Each c In Range("F11", Cells(11, lngCol))​
c.EntireColumn.Hidden = c.Value <> Range("A3").Value​
Next c

Application.ScreenUpdating = True
End Sub

MACRO 2:

Sub hide_columns2()

Dim lngCol As Long, c As Range

lngCol = Cells(16, Columns.Count).End(xlToLeft).Column

Application.ScreenUpdating = False

Cells.Columns.Hidden = False

For Each c In Range("F16", Cells(16, lngCol))​
c.EntireColumn.Hidden = c.Value <> Range("D1").Value​
Next c

Application.ScreenUpdating = True
End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,203,485
Messages
6,055,686
Members
444,807
Latest member
RustyExcel

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