PC Review


Reply
Thread Tools Rate Thread

How do I hide certain columns in a sheet with merged cells in a row using a macro?

 
 
Dan E
Guest
Posts: n/a
 
      3rd Dec 2006
I'm having trouble with a macro that is meant to hide selected columns in a
worksheet (see below). Not only does it hide the columns I want hidden, but
it also hides all columns between and to the left of the selected range.
Testing on a blank sheet I've verified that the problem appears to be that I
have title rows in the sheet, which use merged cells in a row, basically
covering the whole range of columns the macro operates on, so that for
example A7:AQ7 are merged into a single cell. Could anyone suggest a way
round it, please? I realize that I could include in the macro actions that
would unmerge the title cells before running the hide part of the macro,
then merge the title cells again, BUT the title cells are many and vary in
cell coverage, and it would require a great deal of selecting. I feel that
there must be a way round this, but I have very little VBA knowledge. All
suggestions and help VERY gratefully received and acknowledged.

Macro:-
_______
Sub Hide_2wk_Macro3()

Range( _
"C:C,D,F:F,G:G,I:I,J:J,L:L,M:M,O:O,P:P,R:R,S:S,U:U,V:V,Z:Z,AA:AA,AD:AD,AC:AC,AF:AF,AG:AG,AI:AI,AJ:AJ,AL:AL,AM:AM,AO:AO,AP:AP,AR:AR,AS:AS"
_
).Select
Range("AS1").Activate
Selection.EntireColumn.Hidden = True
Range("A5").Activate
End Sub
_________
TIA

Dan E
--
Dan E
webbie(removethis)@preferredcountry.com


 
Reply With Quote
 
 
 
 
Don Guillett
Guest
Posts: n/a
 
      3rd Dec 2006
maybe

title title
col a col b

--
Don Guillett
SalesAid Software
(E-Mail Removed)
"Dan E" <webbie(removethis)@preferredcountry.com> wrote in message
news:(E-Mail Removed)...
> I'm having trouble with a macro that is meant to hide selected columns in
> a worksheet (see below). Not only does it hide the columns I want hidden,
> but it also hides all columns between and to the left of the selected
> range. Testing on a blank sheet I've verified that the problem appears to
> be that I have title rows in the sheet, which use merged cells in a row,
> basically covering the whole range of columns the macro operates on, so
> that for example A7:AQ7 are merged into a single cell. Could anyone
> suggest a way round it, please? I realize that I could include in the
> macro actions that would unmerge the title cells before running the hide
> part of the macro, then merge the title cells again, BUT the title cells
> are many and vary in cell coverage, and it would require a great deal of
> selecting. I feel that there must be a way round this, but I have very
> little VBA knowledge. All suggestions and help VERY gratefully received
> and acknowledged.
>
> Macro:-
> _______
> Sub Hide_2wk_Macro3()
>
> Range( _
>
> "C:C,D,F:F,G:G,I:I,J:J,L:L,M:M,O:O,P:P,R:R,S:S,U:U,V:V,Z:Z,AA:AA,AD:AD,AC:AC,AF:AF,AG:AG,AI:AI,AJ:AJ,AL:AL,AM:AM,AO:AO,AP:AP,AR:AR,AS:AS"
> _
> ).Select
> Range("AS1").Activate
> Selection.EntireColumn.Hidden = True
> Range("A5").Activate
> End Sub
> _________
> TIA
>
> Dan E
> --
> Dan E
> webbie(removethis)@preferredcountry.com
>



 
Reply With Quote
 
Dan E
Guest
Posts: n/a
 
      3rd Dec 2006
Correction - just tested again on a blank sheet with merged cells covering
all or portions of rows in the range, and this macro works OK on that sheet.
THEN I tested the same macro on the for-real sheet, and it worked like a
charm. Sorry to have troubled you all!

Macro that worked:-
________________
Sub Hide_2wk_new_recorded()

Range( _
"C:C,D,F:F,G:G,I:I,J:J,L:L,M:M,O:O,P:P,R:R,S:S,U:U,V:V,Z:Z,AA:AA,AC:AC,AD:AD,AF:AF,AG:AG,AI:AI,AJ:AJ,AL:AL,AM:AM,AO:AO,AP104:AP105,AR:AR,AS:AS"
_
).Select
Selection.EntireColumn.Hidden = True
Range( _
"A5:B5,E5:E5,H5:H5,K5:K5,N5:N5,Q5:Q5,T5:T5,V5:Y5,AB5:AB5,AE5:AE5,AH5:AH5,AK5:AK5,AN5:AN5,AQ5:AQ5"
_
).Select
Selection.EntireColumn.Hidden = False
Range("A5").Activate
End Sub
_______________
Dan E

"Dan E" <webbie(removethis)@preferredcountry.com> wrote in message
news:(E-Mail Removed)...
> I'm having trouble with a macro that is meant to hide selected columns in
> a worksheet (see below). Not only does it hide the columns I want hidden,
> but it also hides all columns between and to the left of the selected
> range. Testing on a blank sheet I've verified that the problem appears to
> be that I have title rows in the sheet, which use merged cells in a row,
> basically covering the whole range of columns the macro operates on, so
> that for example A7:AQ7 are merged into a single cell. Could anyone
> suggest a way round it, please? I realize that I could include in the
> macro actions that would unmerge the title cells before running the hide
> part of the macro, then merge the title cells again, BUT the title cells
> are many and vary in cell coverage, and it would require a great deal of
> selecting. I feel that there must be a way round this, but I have very
> little VBA knowledge. All suggestions and help VERY gratefully received
> and acknowledged.
>
> Macro:-
> _______
> Sub Hide_2wk_Macro3()
>
> Range( _
>
> "C:C,D,F:F,G:G,I:I,J:J,L:L,M:M,O:O,P:P,R:R,S:S,U:U,V:V,Z:Z,AA:AA,AD:AD,AC:AC,AF:AF,AG:AG,AI:AI,AJ:AJ,AL:AL,AM:AM,AO:AO,AP:AP,AR:AR,AS:AS"
> _
> ).Select
> Range("AS1").Activate
> Selection.EntireColumn.Hidden = True
> Range("A5").Activate
> End Sub
> _________
> TIA
>
> Dan E
> --
> Dan E
> webbie(removethis)@preferredcountry.com
>



 
Reply With Quote
 
Tom Ogilvy
Guest
Posts: n/a
 
      3rd Dec 2006
Remove the Select statement - I believe it is the source of your problem.
Sub Hide_2wk_Macro3()

Range( _
"C:C,D,F:F,G:G,I:I,J:J,L:L,M:M,O:O,P:P,R:R,S:S,U:U,V:V,Z:Z,AA:AA,AD:AD
& ,AC:AC,AF:AF,AG:AG,AI:AI,AJ:AJ,AL:AL,AM:AM,AO:AO,AP:AP,AR:AR,AS:AS" _
).EntireColumn.Hidden = True
Range("A5").Activate
End Sub

--
Regards,
Tom Ogilvy

"Dan E" <webbie(removethis)@preferredcountry.com> wrote in message
news:(E-Mail Removed)...
> I'm having trouble with a macro that is meant to hide selected columns in
> a worksheet (see below). Not only does it hide the columns I want hidden,
> but it also hides all columns between and to the left of the selected
> range. Testing on a blank sheet I've verified that the problem appears to
> be that I have title rows in the sheet, which use merged cells in a row,
> basically covering the whole range of columns the macro operates on, so
> that for example A7:AQ7 are merged into a single cell. Could anyone
> suggest a way round it, please? I realize that I could include in the
> macro actions that would unmerge the title cells before running the hide
> part of the macro, then merge the title cells again, BUT the title cells
> are many and vary in cell coverage, and it would require a great deal of
> selecting. I feel that there must be a way round this, but I have very
> little VBA knowledge. All suggestions and help VERY gratefully received
> and acknowledged.
>
> Macro:-
> _______
> Sub Hide_2wk_Macro3()
>
> Range( _
>
> "C:C,D,F:F,G:G,I:I,J:J,L:L,M:M,O:O,P:P,R:R,S:S,U:U,V:V,Z:Z,AA:AA,AD:AD,AC:AC,AF:AF,AG:AG,AI:AI,AJ:AJ,AL:AL,AM:AM,AO:AO,AP:AP,AR:AR,AS:AS"
> _
> ).Select
> Range("AS1").Activate
> Selection.EntireColumn.Hidden = True
> Range("A5").Activate
> End Sub
> _________
> TIA
>
> Dan E
> --
> Dan E
> webbie(removethis)@preferredcountry.com
>



 
Reply With Quote
 
Dan E
Guest
Posts: n/a
 
      3rd Dec 2006
Many thanks, Tom - that works wonderfully!

Dan
"Tom Ogilvy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Remove the Select statement - I believe it is the source of your problem.
> Sub Hide_2wk_Macro3()
>
> Range( _
>
> "C:C,D,F:F,G:G,I:I,J:J,L:L,M:M,O:O,P:P,R:R,S:S,U:U,V:V,Z:Z,AA:AA,AD:AD &
> ,AC:AC,AF:AF,AG:AG,AI:AI,AJ:AJ,AL:AL,AM:AM,AO:AO,AP:AP,AR:AR,AS:AS" _
> ).EntireColumn.Hidden = True
> Range("A5").Activate
> End Sub
>
> --
> Regards,
> Tom Ogilvy
>
> "Dan E" <webbie(removethis)@preferredcountry.com> wrote in message
> news:(E-Mail Removed)...
>> I'm having trouble with a macro that is meant to hide selected columns in
>> a worksheet (see below). Not only does it hide the columns I want
>> hidden, but it also hides all columns between and to the left of the
>> selected range. Testing on a blank sheet I've verified that the problem
>> appears to be that I have title rows in the sheet, which use merged cells
>> in a row, basically covering the whole range of columns the macro
>> operates on, so that for example A7:AQ7 are merged into a single cell.
>> Could anyone suggest a way round it, please? I realize that I could
>> include in the macro actions that would unmerge the title cells before
>> running the hide part of the macro, then merge the title cells again, BUT
>> the title cells are many and vary in cell coverage, and it would require
>> a great deal of selecting. I feel that there must be a way round this,
>> but I have very little VBA knowledge. All suggestions and help VERY
>> gratefully received and acknowledged.
>>
>> Macro:-
>> _______
>> Sub Hide_2wk_Macro3()
>>
>> Range( _
>>
>> "C:C,D,F:F,G:G,I:I,J:J,L:L,M:M,O:O,P:P,R:R,S:S,U:U,V:V,Z:Z,AA:AA,AD:AD,AC:AC,AF:AF,AG:AG,AI:AI,AJ:AJ,AL:AL,AM:AM,AO:AO,AP:AP,AR:AR,AS:AS"
>> _
>> ).Select
>> Range("AS1").Activate
>> Selection.EntireColumn.Hidden = True
>> Range("A5").Activate
>> End Sub
>> _________
>> TIA
>>
>> Dan E
>> --
>> Dan E
>> webbie(removethis)@preferredcountry.com
>>

>
>



 
Reply With Quote
 
Dan E
Guest
Posts: n/a
 
      3rd Dec 2006
Thanks, Don. The titles need to be LARGE and span several columns, however.
Tom's solution below works well, if you need to do something similar.

Dan
"Don Guillett" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> maybe
>
> title title
> col a col b
>
> --
> Don Guillett
> SalesAid Software
> (E-Mail Removed)
> "Dan E" <webbie(removethis)@preferredcountry.com> wrote in message
> news:(E-Mail Removed)...
>> I'm having trouble with a macro that is meant to hide selected columns in
>> a worksheet (see below). Not only does it hide the columns I want
>> hidden, but it also hides all columns between and to the left of the
>> selected range. Testing on a blank sheet I've verified that the problem
>> appears to be that I have title rows in the sheet, which use merged cells
>> in a row, basically covering the whole range of columns the macro
>> operates on, so that for example A7:AQ7 are merged into a single cell.
>> Could anyone suggest a way round it, please? I realize that I could
>> include in the macro actions that would unmerge the title cells before
>> running the hide part of the macro, then merge the title cells again, BUT
>> the title cells are many and vary in cell coverage, and it would require
>> a great deal of selecting. I feel that there must be a way round this,
>> but I have very little VBA knowledge. All suggestions and help VERY
>> gratefully received and acknowledged.
>>
>> Macro:-
>> _______
>> Sub Hide_2wk_Macro3()
>>
>> Range( _
>>
>> "C:C,D,F:F,G:G,I:I,J:J,L:L,M:M,O:O,P:P,R:R,S:S,U:U,V:V,Z:Z,AA:AA,AD:AD,AC:AC,AF:AF,AG:AG,AI:AI,AJ:AJ,AL:AL,AM:AM,AO:AO,AP:AP,AR:AR,AS:AS"
>> _
>> ).Select
>> Range("AS1").Activate
>> Selection.EntireColumn.Hidden = True
>> Range("A5").Activate
>> End Sub
>> _________
>> TIA
>>
>> Dan E
>> --
>> Dan E
>> webbie(removethis)@preferredcountry.com
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RE: Copy Visible Cells in Sheet with Merged and Hidden Cells FSt1 Microsoft Excel Misc 1 2nd Oct 2008 12:51 AM
How to show columns/cells in sheet but hide them in print? Jeff Korn Microsoft Excel Programming 4 25th May 2008 05:54 PM
How to show columns/cells in sheet but hide them in print? Jeff Korn Microsoft Excel Misc 7 25th May 2008 05:54 PM
If I have a work sheet protected and try to run a macro to hide rows or columns it won't work. Correct? Marc Microsoft Excel Programming 2 12th Jul 2006 04:10 AM
Hide all columns that span a merged cell? =?Utf-8?B?U3R1YXJ0IFBldGVycw==?= Microsoft Excel Programming 8 4th Apr 2006 10:32 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:02 PM.