Solved

Excel Macro to hide columns in different worksheet

Posted on 2016-09-13
3
74 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 30

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 30

Expert Comment

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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

829 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