?
Solved

Unhide Columns Using Column name

Posted on 2013-12-10
16
Medium Priority
?
256 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
[X]
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
  • 6
  • 5
  • 5
16 Comments
 
LVL 31

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 31

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
Industry Leaders: 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!

 

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 31

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 31

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 2000 total points
ID: 39709401
Ok then try

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

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

801 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