Solved

Unhide Columns Using Column name

Posted on 2013-12-10
16
246 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
 

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article will show you how to use shortcut menus in the Access run-time environment.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now