Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
SandyR
 
Posts: n/a
Default macro to hide rows across several worksheets fails

I recorded a macro by selecting a bunch of worksheets, then selecting a range
of rows, then going to the format menu and selecting column hide. When I
carry out this procedure by hand it works fine, but when I run the macro, it
only hides the rows in the first worksheet. Anyone know why or what I might
be doing wrong.

Thanks!
  #2   Report Post  
Aussie CPA
 
Posts: n/a
Default

Sandy,
You could try adding the following code into your macro:

Dim Sheetnumber
Sheetnumber = 1
Do
"INSERT EXISTING MACRO CODE HERE"
Sheetnumber = Sheetnumber + 1
Loop Until Sheetnumber = ActiveWorkbook.Worksheets.Count

This code will run the code on each sheet in the active workbook.





"SandyR" wrote:

I recorded a macro by selecting a bunch of worksheets, then selecting a range
of rows, then going to the format menu and selecting column hide. When I
carry out this procedure by hand it works fine, but when I run the macro, it
only hides the rows in the first worksheet. Anyone know why or what I might
be doing wrong.

Thanks!

  #3   Report Post  
SandyR
 
Posts: n/a
Default

That seems like a good work around, and I will probably use it, but I would
like to understand why this doesn't work as is. I am still trying to
understand the underlying principles of this object oriented stuff.

"Aussie CPA" wrote:

Sandy,
You could try adding the following code into your macro:

Dim Sheetnumber
Sheetnumber = 1
Do
"INSERT EXISTING MACRO CODE HERE"
Sheetnumber = Sheetnumber + 1
Loop Until Sheetnumber = ActiveWorkbook.Worksheets.Count

This code will run the code on each sheet in the active workbook.





"SandyR" wrote:

I recorded a macro by selecting a bunch of worksheets, then selecting a range
of rows, then going to the format menu and selecting column hide. When I
carry out this procedure by hand it works fine, but when I run the macro, it
only hides the rows in the first worksheet. Anyone know why or what I might
be doing wrong.

Thanks!

  #4   Report Post  
PCLIVE
 
Posts: n/a
Default

Post your code so someone can look at it.


"SandyR" wrote in message
...
I recorded a macro by selecting a bunch of worksheets, then selecting a
range
of rows, then going to the format menu and selecting column hide. When I
carry out this procedure by hand it works fine, but when I run the macro,
it
only hides the rows in the first worksheet. Anyone know why or what I
might
be doing wrong.

Thanks!



  #5   Report Post  
SandyR
 
Posts: n/a
Default

Here is one of my attempts. Note that there are other worksheets in the
workbook that are not selected, and that the range and clear statements work
for all the selected worksheets:

Sub setup()
'
' setup Macro
' Macro recorded 9/28/2005 by SR
'
' Keyboard Shortcut: Ctrl+Shift+S
'
Sheets(Array("0110", "0120", "0130", "0141", "0142", "0143", "0144",
"0145", "0146", _
"0147", "0160", "0170")).Select
Sheets("0110").Activate
Columns("A:AB").Select
Selection.EntireColumn.Hidden = False
Rows("1:55").Select
Selection.EntireRow.Hidden = False

' Clear values in estimated total expenditure, level A, level B, department
request
' manager reccomend and council approved columns

Range("K8:K15").Select
Selection.ClearContents
. . . (more select and clear statements)

Rows("28:36").Select
Selection.EntireRow.Hidden = True

"SandyR" wrote:

I recorded a macro by selecting a bunch of worksheets, then selecting a range
of rows, then going to the format menu and selecting column hide. When I
carry out this procedure by hand it works fine, but when I run the macro, it
only hides the rows in the first worksheet. Anyone know why or what I might
be doing wrong.

Thanks!



  #6   Report Post  
PCLIVE
 
Posts: n/a
Default

Sorry Sandy,

It looks like VBA does not work with grouped worksheets. See Tom's reply
below:
----------------------------------------------------------------------------------

for the most part, VBA does not support actions performed on grouped sheets.
In some cases, you can work around it by using Selection, but it appears
that is not the case for you. Just loop through the sheets and perform the
action.

--
Regards,
Tom Ogilvy

"PCLIVE" wrote in message
...
I saw another post regarding problems with hiding columns using a macro.

I run the macro recorder, group several sheets together, and then select
multiple columns on the sheet. Goto format and select the option to
columns, hide. I stop the macro recorder. When checking each of the

sheets
that were grouped together, the selected columns on each worksheet has

been
hidden. That is what I want. If I unhide everything and then run the

macro
I just recorded, it only hides the columns on the active sheet. Does

anyone
know why this is happening and how I can get it to the same columns on all
of the grouped sheets, just as if I was doing it manually.

This is what gets recorded my the macro recorder.

Rows("1:17").Select
Sheets(Array("Sheet2", "Sheet3", "Sheet4")).Select
Sheets("Sheet4").Activate
Selection.EntireRow.Hidden = True
Rows("25:39").Select
Selection.EntireRow.Hidden = True
Columns("B:F").Select
Range("B18").Activate
Selection.EntireColumn.Hidden = True



Thanks,
Paul




"SandyR" wrote in message
...
Here is one of my attempts. Note that there are other worksheets in the
workbook that are not selected, and that the range and clear statements
work
for all the selected worksheets:

Sub setup()
'
' setup Macro
' Macro recorded 9/28/2005 by SR
'
' Keyboard Shortcut: Ctrl+Shift+S
'
Sheets(Array("0110", "0120", "0130", "0141", "0142", "0143", "0144",
"0145", "0146", _
"0147", "0160", "0170")).Select
Sheets("0110").Activate
Columns("A:AB").Select
Selection.EntireColumn.Hidden = False
Rows("1:55").Select
Selection.EntireRow.Hidden = False

' Clear values in estimated total expenditure, level A, level B,
department
request
' manager reccomend and council approved columns

Range("K8:K15").Select
Selection.ClearContents
. . . (more select and clear statements)

Rows("28:36").Select
Selection.EntireRow.Hidden = True

"SandyR" wrote:

I recorded a macro by selecting a bunch of worksheets, then selecting a
range
of rows, then going to the format menu and selecting column hide. When I
carry out this procedure by hand it works fine, but when I run the macro,
it
only hides the rows in the first worksheet. Anyone know why or what I
might
be doing wrong.

Thanks!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
hide a worksheet so that a macro can still find it frendabrenda1 Excel Worksheet Functions 1 June 17th 05 04:30 PM
hide rows with macro Macro to hide rows in spreadwsheet Excel Discussion (Misc queries) 3 May 12th 05 05:02 PM
Button fails to call macro when open an Excel via Intranet tigertax Excel Discussion (Misc queries) 1 April 12th 05 10:21 AM
.ONACTION macro call fails Wayne Excel Discussion (Misc queries) 2 March 2nd 05 05:10 PM
HELP! How do you--> Lock a set of rows but also link worksheets to FRUSTRATED Excel Discussion (Misc queries) 6 December 29th 04 10:05 PM


All times are GMT +1. The time now is 01:58 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"