ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   macro - hides everything and not just certain columns as recorded (https://www.excelbanter.com/excel-programming/296978-macro-hides-everything-not-just-certain-columns-recorded.html)

sonar[_6_]

macro - hides everything and not just certain columns as recorded
 
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

--
Message posted from http://www.ExcelForum.com


JE McGimpsey

macro - hides everything and not just certain columns as recorded
 
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

In article ,
sonar wrote:

Hi

I have a problem that when I play the following macros, it hides
everything, and I mean everything and not just the columns as
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 nothing
more.
:confused:


---
Message posted from http://www.ExcelForum.com/


sonar[_7_]

macro - hides everything and not just certain columns as recorded
 
Hi

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

--
Message posted from http://www.ExcelForum.com


Dave Peterson[_3_]

macro - hides everything and not just certain columns as recorded
 
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.

"sonar <" wrote:

Hi

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

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson


JE McGimpsey

macro - hides everything and not just certain columns as recorded
 
In article ,
sonar wrote:

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.


All times are GMT +1. The time now is 04:29 AM.

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