Hide/Unhide

jarhead58

Active Member
Joined
Sep 21, 2017
Messages
367
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
[TABLE="width: 300, align: center"]
<tbody>[TR]
[TD]Text1 [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD] [/TD]
[TD]11/7/19[/TD]
[/TR]
[TR]
[TD]Text2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]x[/TD]
[/TR]
[TR]
[TD]Text3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]11/7/19[/TD]
[/TR]
[TR]
[TD]Text4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]11/7/19[/TD]
[/TR]
[TR]
[TD]Text5[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]11/7/19[/TD]
[/TR]
[TR]
[TD]Text6[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]11/7/19[/TD]
[/TR]
</tbody>[/TABLE]


Sheet2

A B C D E F [TABLE="width: 300, align: center"]
<tbody>[TR]
[TD] [/TD]
[TD]Text1[/TD]
[TD]Text2[/TD]
[TD]Text3[/TD]
[TD]Text4[/TD]
[TD]Text5[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
How about
Code:
Sub jarhead()
    Dim Cl As Range, Fnd As Range
    
    For Each Cl In Range("F2:F40")
        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 Sub
 
Upvote 0
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
[TABLE="width: 300, align: center"]
<tbody>[TR]
[TD]Text1[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]11/7/19[/TD]
[/TR]
[TR]
[TD]Text2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]x[/TD]
[/TR]
[TR]
[TD]Text3[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]11/7/19[/TD]
[/TR]
[TR]
[TD]Text4[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]11/7/19[/TD]
[/TR]
[TR]
[TD]Text5[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]11/7/19[/TD]
[/TR]
[TR]
[TD]Text6[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]11/7/19[/TD]
[/TR]
</tbody>[/TABLE]


Sheet2

A B C D E F [TABLE="width: 300, align: center"]
<tbody>[TR]
[TD][/TD]
[TD]Text1[/TD]
[TD]Text2[/TD]
[TD]Text3[/TD]
[TD]Text4[/TD]
[TD]Text5[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Please disregard the last post. Can't get the table to copy over to the message!
 
Upvote 0
How about
Code:
Sub jarhead()
    Dim Cl As Range, Fnd As Range
    
    For Each Cl In Range("F2:F40")
        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 Sub

LOL!

So you actually made sense of it huh?

For future reference, how can I get an excel table to copy into the message, if possible?
 
Upvote 0
Lets see if this works.

Sheet1

Excel 2016 (Windows) 32 bit
[Table="width:, class:head"][tr=bgcolor:#E0E0F0][th] [/th][th]
A
[/th][th]
B
[/th][th]
C
[/th][th]
D
[/th][th]
E
[/th][th]
F
[/th][/tr]
[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
1
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
2
[/td][td]text1[/td][td][/td][td][/td][td][/td][td]
[/td][td]
11/7/2019​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
3
[/td][td]text2[/td][td][/td][td][/td][td][/td][td]
[/td][td]
11/7/2019​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
4
[/td][td]text3[/td][td][/td][td][/td][td][/td][td]
[/td][td]no date[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
5
[/td][td]text4[/td][td][/td][td][/td][td][/td][td]
[/td][td]
11/7/2019​
[/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
6
[/td][td]text5[/td][td][/td][td][/td][td][/td][td]
[/td][td]
11/7/2019​
[/td][/tr]
[/table]
[Table="width:, class:grid"][tr][td]Sheet: Sheet1[/td][/tr][/table]


Sheet2

Excel 2016 (Windows) 32 bit
[Table="width:, class:head"][tr=bgcolor:#E0E0F0][th] [/th][th]
A
[/th][th]
B
[/th][th]
C
[/th][th]
D
[/th][th]
E
[/th][th]
F
[/th][/tr]
[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
1
[/td][td][/td][td]text1[/td][td]text2[/td][td]text3[/td][td]text4[/td][td][/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
2
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
3
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
4
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]


[tr=bgcolor:#FFFFFF][td=bgcolor:#E0E0F0]
5
[/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][/tr]
[/table]
[Table="width:, class:grid"][tr][td]Sheet: Sheet2[/td][/tr][/table]
 
Upvote 0
I only want the column that didn't have a date to be hidden on sheet2. Hopefully that clears it up a little lol!
 
Upvote 0
Assuming it was on this line
Code:
Set Fnd = Sheets("[COLOR=#ff0000]sheet2[/COLOR]").Rows(1).Find(Cl.Offset(, -5).Value, , , xlWhole, , , False, , False)
Change the value in red to match your actual sheet name
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,021
Members
452,374
Latest member
keccles

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