Forum Discussion
jumpcut
Dec 31, 2019Copper Contributor
Hide columns using check boxes
I'm new to Excel programming but seem to be making progress and am enjoying the power and flexibility of VBA. I have a spreadsheet that has two sheets. Sheet1 contains 25 columns of data. At any give...
- Dec 31, 2019
In that case, you should first locate a column with header "Notes" on Sheet1 and if it is found, you hide or unhide it irrespective of which column contains that header.
Please try it like this and don't forget to tweak the Sheet Names in the code...
Dim ws1 As Worksheet Dim ws2 As Worksheet Dim headerCell As Range Set ws1 = Worksheets("Sheet1") Set ws2 = Worksheets("Sheet2") 'Assuming headers are in Row1 on Sheet1 Set headerCell = ws1.Rows(1).Find(what:="Notes", lookat:=xlWhole) If Not headerCell Is Nothing Then headerCell.EntireColumn.Hidden = Not ws2.Range("A8") Else MsgBox "The column with header 'Notes' was not found.", vbExclamation Exit Sub End If
jumpcut
Dec 31, 2019Copper Contributor
Works perfectly! Many thanks for your help. A very Happy New Year to you!
Subodh_Tiwari_sktneer
Jan 01, 2020Silver Contributor