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
Solved

Unhide Columns Using Column name

Posted on 2013-12-10
16
250 Views
Last Modified: 2013-12-10
Hello,

I am trying to unhide 2 columns (A and B) from a table using the following code:
.Range("A:B").EntireColumn.Hidden = False

I would like to use  the column names ("Name1" and "Name2") instead of the column letters/ numbers (A and B).

Could you please help me write this code?

Thank you
0
Comment
Question by:jmac001
  • 6
  • 5
  • 5
16 Comments
 
LVL 29

Expert Comment

by:gowflow
ID: 39709186
What do you mean by Name1 and Name2 ? are they the value in Row 1 of these 2 columns ?
gowflow
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39709203
Try something like

Range("Table5[[#Headers],[Column3]]").EntireColumn.Select
0
 
LVL 29

Expert Comment

by:gowflow
ID: 39709221
Is this what you want ?
I created 2 ranges first one Name1 is entirecolumn A Name2 entirecolumnB
Just select Name1 from the upper dropdown cell it will show ColA and same with name2

then activate macros and press on the button Hide/Show and look at the instruction

Sub test(showhide As Boolean)
Range("Name1:Name2").EntireColumn.Hidden = showhide

End Sub

Open in new window


Is this what you want ?
gowflow
ShowHide.xls
0
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.

 

Author Comment

by:jmac001
ID: 39709225
gowflow,

The names are indeed the values in Row 1 of the table (the header).
I would need the code to refer to the column names and not absolute numbers so additional columns could be addet to the table in the future.

Thanks
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39709228
Did you try my syntax?
0
 

Author Comment

by:jmac001
ID: 39709256
ssaqibh,

I'm not sure how to read/modify your syntax to my code:

Range("Table5[[#Headers],[Column3]]").EntireColumn.Select
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39709273
Replace those names within the quotes with your own.
0
 
LVL 29

Expert Comment

by:gowflow
ID: 39709277
ok here it is check out the code.
It is for sure a routine that check for the location of the variable you define in Cell M5 input any string there and see what it does.

gowflow
ShowHide.xls
0
 

Author Comment

by:jmac001
ID: 39709325
gowflow,

Your last attachment doesn't have the code  for some reason.
0
 
LVL 29

Expert Comment

by:gowflow
ID: 39709335
yes it does. Activate macroes. Here it is again but it is the same file I just changed the name maybe you used the previous version.
gowflow
ShowHide-V1.xls
0
 

Author Comment

by:jmac001
ID: 39709358
ssaqibh, this is the code after I replaced the names:

Range("InitiativeTbl[[Initiative ID],[Worksheet]]").EntireColumn.Select

It doesn't seem to work though..
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 39709381
Try

Range("InitiativeTbl[[#Headers],[Initiative ID]]").EntireColumn.Select
0
 

Author Comment

by:jmac001
ID: 39709387
gowflow,

the code works but it seems more complex than what I need it to be.
I would just need the table to unhide 2 specific columns "Initiative ID" and "Workstream".
Not sure if we would need the "Hide" button this time. But I will most definitely use this code in the future.

thanks.
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 39709401
Ok then try

Range("InitiativeTbl[[#Headers],[Initiative ID]],InitiativeTbl[[#Headers],[Workstream]]").EntireColumn.Select
0
 
LVL 29

Expert Comment

by:gowflow
ID: 39709410
then ssaqibh code is more straight forward
gowflow
0
 

Author Comment

by:jmac001
ID: 39709454
ssaqibh code works! I only changed the last part from

.. EntireColumn.Select

to

.. EntireColumn.Hidden = False

Thank you so much!
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Learn how to make your own table of contents in Microsoft Word using paragraph styles and the automatic table of contents tool. We'll be using the paragraph styles in Word’s Home toolbar to help you create a table of contents. Type out your initial …
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.

856 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