Help With Macro

  • Thread starter Thread starter Crownman
  • Start date Start date
C

Crownman

Hi all:

I am trying to create a macro that will select several columns on a
page and hide them. Thus far I have the following code:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 7/29/2007 by Crownman
'
' Keyboard Shortcut: Ctrl+k
'
Sheets("SUMMARY").Select
Range("F:F,I:I,L:L,O:O,R:R,X:X").Select
Selection.EntireColumn.Hidden = True
Range("D9").Select
Sheets("Work_area").Select
End Sub

When I run the macro, instead of hiding only the selected columns, it
hides all the columns from D through W. In all cases, the columns I
want to hide contain formulas that are based on the two columns to the
left of the ones to be hidden.

The macro was originally done with the macro recorder - which produced
the same problem.

Can anyone give me any suggestions?

Crownman
 
Are you sure that you don't have hidden columns to start?

Sub Macro1()
with Sheets("SUMMARY")
.Select
.columns.hidden = false
.Range("F:F,I:I,L:L,O:O,R:R,X:X").EntireColumn.Hidden = True
.Range("D9").Select
end with
Sheets("Work_area").Select
End Sub

This does what your code does and eliminates the .selection. And adds a line to
unhide all the columns. But it's essentially the same as your code.

If this doesn't help, I bet you have merged cells in your Summary worksheet.
Depending on the version of excel, you'll have the results you see.
 
Try this. If you have variable columns to be hidden, this can be done using
OFFSET. Give the criteria for more help.

Sub hidecols()'From anywhere in wb
Sheets("summary").Range("f1,i1,l1,o1,r1,x1"). _
EntireColumn.Hidden = True
End Sub
 
Are you sure that you don't have hidden columns to start?

Sub Macro1()
with Sheets("SUMMARY")
.Select
.columns.hidden = false
.Range("F:F,I:I,L:L,O:O,R:R,X:X").EntireColumn.Hidden = True
.Range("D9").Select
end with
Sheets("Work_area").Select
End Sub

This does what your code does and eliminates the .selection. And adds a line to
unhide all the columns. But it's essentially the same as your code.

If this doesn't help, I bet you have merged cells in your Summary worksheet.
Depending on the version of excel, you'll have the results you see.












--

Dave Peterson- Hide quoted text -

- Show quoted text -

Dave:

This worked perfectly. I did have some columns hidden on the Summary
sheet. I just added the references to rehide the columns that were
originally hidden.

I appreciate your help.

Crownman
 
Back
Top