Automatically show columns based on criteria

Scott Browner

New Member
Joined
Mar 28, 2017
Messages
8
I need help showing only columns based on criteria. I have a spreadsheet with Q1, Q2, Q3 and Q4 data. If I type "Q1" into a specific cell (in this case cell C2 which is shaded) I want all of the cells containing Q1 at the top to appear and all of the cells that contain Q2, Q3 and Q4 to be hidden. Here is the spreadsheet that I have been working on so far. Thanks in advance for your help.

Incentive Plan - CumulativeQ1Q1Q2Q3Q4Q1Q2Q3Q4
Prorated Bonus Amounts
Working TimekeeperPositionDate EmployedDate TerminatedAnnual Salary as of EOQ1Annual Salary as of EOQ2Annual Salary as of EOQ3Annual Salary as of EOQ4Q1 BonusQ2 BonusQ3 BonusQ4 Bonus
<colgroup><col width="165" style="width: 124pt; mso-width-source: userset; mso-width-alt: 6034;"> <col width="99" style="width: 74pt; mso-width-source: userset; mso-width-alt: 3620;"> <col width="69" style="width: 52pt; mso-width-source: userset; mso-width-alt: 2523;"> <col width="74" style="width: 56pt; mso-width-source: userset; mso-width-alt: 2706;"> <col width="69" style="width: 52pt; mso-width-source: userset; mso-width-alt: 2523;" span="4"> <col width="59" style="width: 44pt; mso-width-source: userset; mso-width-alt: 2157;" span="4"> <tbody> </tbody>
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
as a worksheet change event
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range, rng
Set rng = Range("e2:l2")
If Target.Row = 2 And Target.Column = 3 Then
Columns("d:m").Hidden = False
For Each c In rng
If c.Value <> Target.Value Then
c.EntireColumn.Hidden = True
End If
Next c
End If
End Sub
 
Upvote 0
Is it possible to put a string in the target field? An example would be; I would like to look at Q1 and Q2 at the same time or Q2 and Q3. Is that possible?
 
Upvote 0
How about
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   Dim Cl As Range
   If Target.CountLarge > 1 Then Exit Sub
   If Target.Address = "$C$2" Then
      Range("D:M").EntireColumn.Hidden = False
      For Each Cl In Range("e2", Cells(2, Columns.Count).End(xlToLeft))
         Cl.EntireColumn.Hidden = Not InStr(1, Target.Value, Cl.Value) > 0
      Next Cl
   End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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