Hiding columns in a named range

  • Thread starter Thread starter malcomio
  • Start date Start date
M

malcomio

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"
 
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).EntireColumn.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
 
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
 
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.
 
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
 
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?
 
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
 
Back
Top