?
Solved

Excel Macro to hide columns in different worksheet

Posted on 2016-09-13
3
Medium Priority
?
90 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 32

Accepted Solution

by:
Subodh Tiwari (Neeraj) earned 2000 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 32

Expert Comment

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
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 use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
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…

764 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