macro - hides everything and not just certain columns as recorded

S

sonar

Hi

I have a problem that when I play the following macros, it hide
everything, and I mean everything and not just the columns a
recorded.

Sub hide()
'
' hide Macro
' Macro recorded 2004/05/02 by
'
' Keyboard Shortcut: Ctrl+h
'
Columns("M:O").Select
Selection.EntireColumn.Hidden = True
Columns("X:Z").Select
Selection.EntireColumn.Hidden = True
Columns("AI:AK").Select
Selection.EntireColumn.Hidden = True
Columns("AT:AV").Select
Selection.EntireColumn.Hidden = True
Columns("BE:BG").Select
Selection.EntireColumn.Hidden = True
Columns("BP:BR").Select
Selection.EntireColumn.Hidden = True
Columns("CA:CC").Select
Selection.EntireColumn.Hidden = True
Columns("CF:CF").Select
Selection.EntireColumn.Hidden = True
Columns("CM:CM").Select
Selection.EntireColumn.Hidden = True
Columns("CR:CR").Select
Selection.EntireColumn.Hidden = True

End Sub

What can I do to make sure it only hides these columns and nothin
more.
:confused
 
J

JE McGimpsey

One way:

Public Sub Hide()
Range("M:O,X:Z,AI:AK,AT:AV,BE:BG,BP:BR,CA:CC,CF:CF,CM:CM,CR:CR") _
.EntireColumn.Hidden = True
End Sub


Note that there's almost never a need to select a range - you can use
the range object directly
 
S

sonar

Hi

I replaced the one I had with the one you gave and I got a sinte
error. Did I do something wrong
 
D

Dave Peterson

J.E.'s code worked for me when I copied from the post to the VBE.

Any chance you introduced extraneous characters (or left some out)?

You may want to post what you pasted.
 
J

JE McGimpsey

sonar said:
I replaced the one I had with the one you gave and I got a sintex
error. Did I do something wrong?

Yes. But I don't know what.

Did you include the line extension characters (" _", space-underscore)
at the end of the long line?

Try copying and pasting.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top