Solved

Excel Macro to hide columns in different worksheet

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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;…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

679 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