ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Hiding columns in a named range (https://www.excelbanter.com/excel-programming/410083-hiding-columns-named-range.html)

malcomio

Hiding columns in a named range
 
Is there a way of hiding columns in named ranges in VBA? I've got a load of
columns that I want to show and hide, but I might want to add other columns
in the worksheets later, so named ranges would make life easier.

I would have thought it was simple, but I just get an error that I'm "unable
to set hidden property of range class"

[email protected]

Hiding columns in a named range
 
Hi
Either of these will hide column 2 in range "tester"

ActiveSheet.Range("tester").Columns(2).Hidden = True

or
ActiveSheet.Range("tester").Cells(1,2).EntireColum n.Hidden = True

There is no Hide method, so this won't work

ActiveSheet.Range("tester").Columns(2).Hide

no matter how tempting it looks!
regards
Paul

On Apr 28, 12:21*pm, malcomio
wrote:
Is there a way of hiding columns in named ranges in VBA? I've got a load of
columns that I want to show and hide, but I might want to add other columns
in the worksheets later, so named ranges would make life easier.

I would have thought it was simple, but I just get an error that I'm "unable
to set hidden property of range class"



[email protected]

Hiding columns in a named range
 

Forgot to mention
You may also find this useful

With ActiveSheet.Range("tester")
.Range(.Columns(2), .Columns(4)).Hidden = True
End With

which will hide columns 2 to 4.
regards
Paul

On Apr 28, 12:32*pm, wrote:
Hi
Either of these will hide column 2 in range "tester"

ActiveSheet.Range("tester").Columns(2).Hidden = True

or
ActiveSheet.Range("tester").Cells(1,2).EntireColum n.Hidden = True

There is no Hide method, so this won't work

ActiveSheet.Range("tester").Columns(2).Hide

no matter how tempting it looks!
regards
Paul

On Apr 28, 12:21*pm, malcomio
wrote:



Is there a way of hiding columns in named ranges in VBA? I've got a load of
columns that I want to show and hide, but I might want to add other columns
in the worksheets later, so named ranges would make life easier.


I would have thought it was simple, but I just get an error that I'm "unable
to set hidden property of range class"- Hide quoted text -


- Show quoted text -



malcomio

Hiding columns in a named range
 
thanks Paul

malcomio

Hiding columns in a named range
 
do you know if pivot tables on a worksheet cause problems? maybe i'm having
problems with worksheet and workbook scope, but I have a range of columns K:V
called "wholeyear", scoped to each worksheet, and when I run the procedure it
hides columns U:AF.

Very strange, especially as this isn't a named range at all.

[email protected]

Hiding columns in a named range
 
Hi
Are you hiding columns relative to some range

e.g. Range("B1:C1").Columns("B:B").Hidden = true

will hide the second column in "B1:C1" i.e. column C of the worksheet.
regards
Paul

On Apr 28, 2:25*pm, malcomio
wrote:
do you know if pivot tables on a worksheet cause problems? maybe i'm having
problems with worksheet and workbook scope, but I have a range of columns K:V
called "wholeyear", scoped to each worksheet, and when I run the procedure it
hides columns U:AF.

Very strange, especially as this isn't a named range at all.



malcomio

Hiding columns in a named range
 
I am hiding columns within a range, and those columns are the values section
of a pivot table.

It seems to be affecting a different range, depending on the number of
columns in the pivot table, even though the named range is set to the values
section. It's very strange. Would you mind if I emailed you an example of the
problem?


[email protected]

Hiding columns in a named range
 
Sure - probably tomorrow when I reply, but I'll reply direct to you.
Paul

On Apr 28, 4:06*pm, malcomio
wrote:
I am hiding columns within a range, and those columns are the values section
of a pivot table.

It seems to be affecting a different range, depending on the number of
columns in the pivot table, even though the named range is set to the values
section. It's very strange. Would you mind if I emailed you an example of the
problem?



Don Guillett

Hiding columns in a named range
 
try this
Sub hidecolinrng()
'Range("hiderng").Cells(1, 3).EntireColumn.Hidden = False
Range("hiderng").Range(Cells(1, 3), Cells(1, 4)).EntireColumn.Hidden = True
'FALSE
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"malcomio" wrote in message
...
Is there a way of hiding columns in named ranges in VBA? I've got a load
of
columns that I want to show and hide, but I might want to add other
columns
in the worksheets later, so named ranges would make life easier.

I would have thought it was simple, but I just get an error that I'm
"unable
to set hidden property of range class"




All times are GMT +1. The time now is 05:58 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com