Hide/Unhide

jarhead58

Active Member
Joined
Sep 21, 2017
Messages
364
Office Version
  1. 2021
Platform
  1. Windows
Good morning!!

To start, I understand that columns can be hidden/unhidden via the Format function on the toolbar. What I need to have happen is to use IsDate to search F2:F40 for a date, none particular, but a date. If not, in the row containing the False return, look at the contents in column A, Match it in Sheet2, whatever column it is in, and hide that column. If it does, just fall through and continue. Let me know if I can detail it better than below;

Sheet1

A B C D E F
Text1 11/7/19
Text2x
Text311/7/19
Text411/7/19
Text511/7/19
Text611/7/19

<tbody>
</tbody>


Sheet2

A B C D E F
Text1Text2Text3Text4Text5

<tbody>
</tbody>
 
A small tweak I forgot to mention. When the book opens again, if text3 now has a date, I was hoping it would unhide. How hard would that be?
 
Last edited:
Upvote 0

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
You could use the workbook open event like
Code:
Private Sub Workbook_Open()
    Dim Cl As Range, Fnd As Range
    Sheets("Sheet2").Columns.Hidden = False
    With Sheets("Sheet1")
        For Each Cl In .Range("F2", .Range("F" & Rows.Count).End(xlUp))
            If Not IsDate(Cl.Value) Then
                Set Fnd = Sheets("sheet2").Rows(1).Find(Cl.Offset(, -5).Value, , , xlWhole, , , False, , False)
                If Not Fnd Is Nothing Then Fnd.EntireColumn.Hidden = True
            End If
        Next Cl
    End With
End Sub
This code needs to go in the "ThisWorkbook" module
 
Upvote 0
You could use the workbook open event like
Code:
Private Sub Workbook_Open()
    Dim Cl As Range, Fnd As Range
    Sheets("Sheet2").Columns.Hidden = False
    With Sheets("Sheet1")
        For Each Cl In .Range("F2", .Range("F" & Rows.Count).End(xlUp))
            If Not IsDate(Cl.Value) Then
                Set Fnd = Sheets("sheet2").Rows(1).Find(Cl.Offset(, -5).Value, , , xlWhole, , , False, , False)
                If Not Fnd Is Nothing Then Fnd.EntireColumn.Hidden = True
            End If
        Next Cl
    End With
End Sub
This code needs to go in the "ThisWorkbook" module

Still doesn't unhide the hid column on reopen with date saved in the x cell
 
Upvote 0
It should unhide all the columns and then re-hide those that don't have a date in col F.
Step through the code using F8, then when the With line is highlighted yellow, have a look at sheet 2. Are all the columns visible?
 
Upvote 0
It should unhide all the columns and then re-hide those that don't have a date in col F.
Step through the code using F8, then when the With line is highlighted yellow, have a look at sheet 2. Are all the columns visible?

No maam! I have F2:F6 with dates but text3, column(C) is still hid!
 
Upvote 0
I have verified that it is in the "Thisworkbook" module.

Code:
Private Sub Workbook_Open() Dim Cl As Range, Fnd As Range
    With Sheets("Sheet1")
        For Each Cl In .Range("F2", .Range("F" & Rows.Count).End(xlUp))
            If Not IsDate(Cl.Value) Then
                Set Fnd = Sheets("sheet2").Rows(1).Find(Cl.Offset(, -5).Value, , , xlWhole, , , False, , False)
                If Not Fnd Is Nothing Then Fnd.EntireColumn.Hidden = True
            End If
        Next Cl
    End With
End Sub
 
Upvote 0
You're missing this line
Code:
Sheets("Sheet2").Columns.Hidden = False
As for
The last time I checked I was definitely a sir ;)
 
Upvote 0
You're missing this line
Code:
Sheets("Sheet2").Columns.Hidden = False
As for The last time I checked I was definitely a sir ;)
Open mouth, insert foot lmao! No offense but your handle made me "assume", stupid word lol! My
sincere apologies sir!
I had to step away from the laptop but I will let you know how it goes! Not sure how that happened, just copied and pasted.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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