Solved

Excel Macro to hide columns in different worksheet

Posted on 2016-09-13
3
49 Views
Last Modified: 2016-09-13
I have a checkbox if the user wants to display columns in a separate worksheet (the worksheet name is "BS").
The following code works to hide the columns on the SAME worksheet where the macro is called (this worksheet name is "Start Here".

Sub AdjustDisplayColumns()
    If Range("C15").Value = "x" Then
        Columns("C:F").EntireColumn.Hidden = False
    Else
        Columns("C:F").EntireColumn.Hidden = True
    End If
End Sub

How can I change this to hide / unhide the columns in the other worksheet ?
0
Comment
Question by:drelinger
  • 2
3 Comments
 
LVL 28

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 500 total points
ID: 41796739
You may try something like this......

Sub AdjustDisplayColumns()
Dim sws As Worksheet, dws As Worksheet
Set sws = Sheets("Start Here")
Set dws = Sheets("BS")
If sws.Range("C15").Value = "x" Then
   dws.Columns("C:F").Hidden = False
Else
   dws.Columns("C:F").Hidden = True
End If
End Sub

Open in new window

0
 

Author Closing Comment

by:drelinger
ID: 41796773
Perfect. thank you for teaching me something new..
0
 
LVL 28

Expert Comment

by:Subodh Tiwari (Neeraj)
ID: 41796780
You're welcome Drelinger! Glad to help.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

What is a Form List Box? (skip if you know this) The forms List Box is the alternative to the ActiveX list box. If you are using excel 2007, you first make sure you have a developer tab (click the Orb)->"Excel Options"->Popular->"Show Developer tab…
Drop Down List with Unique/Distinct Values (enhancing the Combo-Box with a few steps and a little code) David miller (dlmille) Intro Have you ever created a data validation list from a database field or spreadsheet column (e.g., Zip Codes or Co…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now