Solved

Excel Macro to hide columns in different worksheet

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

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 29

Expert Comment

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

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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 article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

785 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