Display only columns with certain text

AlexCHI

New Member
Joined
Sep 28, 2017
Messages
19
Hi all,

Please teach me how I can display only columns with certain text in Excel 2007? There are a lot of help on filtering rows but I am hoping to create either a toggle button or set up a reference cell (say "B4") along with a VBA to display columns with selected days only.

For example, method #1 : the user click the toggle button labeled "Sunday" or method #2 : the user inputs "Sunday" in "B4". Then only column T and column AA and all the Sunday columns will show.

Thank you for any help you can think of.


Excel 2007
STUVWXYZAA
6AM Attendance2
7PM Attendance2
8AM & PM Attendance1
9Jan-1Jan-2Jan-3Jan-4Jan-5Jan-6Jan-7Jan-8
10Days PresentSunMonTueWedThuFriSatSun
111AM & PM
121PM
131AM
14
Main Screen
 
Last edited:
Re: How to display only columns with certain text

Hi Alex, code in #6 reduces B4 to 3 letters and then checks T20:NT20, so long as Sunday = sun, Monday = Mon ... Saturday = Sat

Code that checks:
Code:
If Left$(rngB4.Value, 3) <> .Cells(10, y).Value Then
So it shouldn't matter if B4 contains either full name or 3-letter as input.

Test M.A.I.T's code in #5 or corrected one in #6. I assume you haven't used data validation anywhere either.
 
Last edited:
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Re: How to display only columns with certain text

Row 10 from column T onward is formula returning text, e.g. =TEXT(T9,"ddd").
Try this in a copy of your workbook. Columns should hide/unhide automatically as you enter/delete values (full or short) in B4. I have assumed that dates are continuous by day across row 10.
To implement ..
1. Right click the sheet name tab and choose "View Code".
2. Copy and Paste the code below into the main right hand pane that opens at step 1.
3. Close the Visual Basic window & test.
4. Your workbook will need to be saved as a macro-enabled workbook (*.xlsm).

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
  Dim sDay As String
  Dim rFound As Range
  Dim c As Long
  
  If Not Intersect(Target, Range("B4")) Is Nothing Then
    Application.ScreenUpdating = False
    sDay = Left(Range("B4").Value, 3)
    Columns("T:NT").Hidden = False
    If Len(sDay) > 0 Then
      Set rFound = Range("S10:NT10").Find(What:=sDay, After:=Range("S10"), LookIn:=xlValues, LookAt:=xlPart, MatchCase:=False, SearchDirection:=xlNext, SearchFormat:=False)
      If Not rFound Is Nothing Then
        Columns("T:NT").Hidden = True
        For c = rFound.Column To Columns("NT").Column Step 7
          Columns(c).Hidden = False
        Next c
      End If
    End If
    Application.ScreenUpdating = True
  End If
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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