Solved

Unhide Columns Using Column name

Posted on 2013-12-10
16
249 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 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