Unhide Columns Using Column name

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
jmac001Asked:
Who is Participating?
 
Saqib Husain, SyedConnect With a Mentor EngineerCommented:
Ok then try

Range("InitiativeTbl[[#Headers],[Initiative ID]],InitiativeTbl[[#Headers],[Workstream]]").EntireColumn.Select
0
 
gowflowCommented:
What do you mean by Name1 and Name2 ? are they the value in Row 1 of these 2 columns ?
gowflow
0
 
Saqib Husain, SyedEngineerCommented:
Try something like

Range("Table5[[#Headers],[Column3]]").EntireColumn.Select
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
gowflowCommented:
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
 
jmac001Author Commented:
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
 
Saqib Husain, SyedEngineerCommented:
Did you try my syntax?
0
 
jmac001Author Commented:
ssaqibh,

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

Range("Table5[[#Headers],[Column3]]").EntireColumn.Select
0
 
Saqib Husain, SyedEngineerCommented:
Replace those names within the quotes with your own.
0
 
gowflowCommented:
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
 
jmac001Author Commented:
gowflow,

Your last attachment doesn't have the code  for some reason.
0
 
gowflowCommented:
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
 
jmac001Author Commented:
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
 
Saqib Husain, SyedEngineerCommented:
Try

Range("InitiativeTbl[[#Headers],[Initiative ID]]").EntireColumn.Select
0
 
jmac001Author Commented:
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
 
gowflowCommented:
then ssaqibh code is more straight forward
gowflow
0
 
jmac001Author Commented:
ssaqibh code works! I only changed the last part from

.. EntireColumn.Select

to

.. EntireColumn.Hidden = False

Thank you so much!
0
All Courses

From novice to tech pro — start learning today.