ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Group Worksheets (https://www.excelbanter.com/excel-programming/338660-group-worksheets.html)

Karen

Group Worksheets
 
How do you group worksheets in a macro so I can insert a row in the same
place in all worksheets? The problem is I will not know the names nor the
number of worksheets in the file as the user will add worksheets when needed.

Any and all help will be greatly appreciated.


Chip Pearson

Group Worksheets
 
Try something like the following:

Dim S1 As String
Dim S2 As String
Dim Arr() As String
S1 = "SHeet1"
S2 = "Sheet2"
ReDim Arr(1 To 2)
Arr(1) = S1
Arr(2) = S2
Worksheets(Arr).Select



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Karen" wrote in message
...
How do you group worksheets in a macro so I can insert a row in
the same
place in all worksheets? The problem is I will not know the
names nor the
number of worksheets in the file as the user will add
worksheets when needed.

Any and all help will be greatly appreciated.




bill k

Group Worksheets
 

Sub addline()
For Each Sheet In Sheets
On Error Resume Next
Sheet.Select
Rows(15).Insert
Next
Sheet1.Select

End Sub

or something like this {{;

--
bill

-----------------------------------------------------------------------
bill k's Profile: http://www.excelforum.com/member.php...info&userid=82
View this thread: http://www.excelforum.com/showthread.php?threadid=40024


Karen

Group Worksheets
 
Thanks, but this didn't work. I ended up with a runtime error on the last
line. What I need to do is group worksheets (the names and number of them
will be deterimined by the users) so I can insert an identiical row in each
of these worksheets. When I wrote the macro it recorded just the existing
worksheets. I have been trying to use the worksheet.count command, but am
not familiar enough with the array feature to know what to do next with that
number.

Thanks for helping me out.



"Chip Pearson" wrote:

Try something like the following:

Dim S1 As String
Dim S2 As String
Dim Arr() As String
S1 = "SHeet1"
S2 = "Sheet2"
ReDim Arr(1 To 2)
Arr(1) = S1
Arr(2) = S2
Worksheets(Arr).Select



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Karen" wrote in message
...
How do you group worksheets in a macro so I can insert a row in
the same
place in all worksheets? The problem is I will not know the
names nor the
number of worksheets in the file as the user will add
worksheets when needed.

Any and all help will be greatly appreciated.





Jim Thomlinson[_4_]

Group Worksheets
 
Assuming you want the changes made to all of the selected sheets (selected by
the user) then this might do

Sub AllSheets()
Dim wks As Worksheet

For Each wks In ActiveWindow.SelectedSheets
MsgBox wks.Name
wks.Rows(5).Insert
Next wks
End Sub
--
HTH...

Jim Thomlinson


"Karen" wrote:

Thanks, but this didn't work. I ended up with a runtime error on the last
line. What I need to do is group worksheets (the names and number of them
will be deterimined by the users) so I can insert an identiical row in each
of these worksheets. When I wrote the macro it recorded just the existing
worksheets. I have been trying to use the worksheet.count command, but am
not familiar enough with the array feature to know what to do next with that
number.

Thanks for helping me out.



"Chip Pearson" wrote:

Try something like the following:

Dim S1 As String
Dim S2 As String
Dim Arr() As String
S1 = "SHeet1"
S2 = "Sheet2"
ReDim Arr(1 To 2)
Arr(1) = S1
Arr(2) = S2
Worksheets(Arr).Select



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Karen" wrote in message
...
How do you group worksheets in a macro so I can insert a row in
the same
place in all worksheets? The problem is I will not know the
names nor the
number of worksheets in the file as the user will add
worksheets when needed.

Any and all help will be greatly appreciated.





Dave Peterson

Group Worksheets
 
Worksheets.select

(if you want to get all of them)

Karen wrote:

How do you group worksheets in a macro so I can insert a row in the same
place in all worksheets? The problem is I will not know the names nor the
number of worksheets in the file as the user will add worksheets when needed.

Any and all help will be greatly appreciated.


--

Dave Peterson

Tom Ogilvy

Group Worksheets
 
The code provided by Chip worked fine for me. Of course if you mispell a
sheet name you would get an error.

How is your user going to determine the name and number - how will you code
have access to this information?

--
Regards,
Tom Ogilvy

"Karen" wrote in message
...
Thanks, but this didn't work. I ended up with a runtime error on the last
line. What I need to do is group worksheets (the names and number of them
will be deterimined by the users) so I can insert an identiical row in

each
of these worksheets. When I wrote the macro it recorded just the existing
worksheets. I have been trying to use the worksheet.count command, but am
not familiar enough with the array feature to know what to do next with

that
number.

Thanks for helping me out.



"Chip Pearson" wrote:

Try something like the following:

Dim S1 As String
Dim S2 As String
Dim Arr() As String
S1 = "SHeet1"
S2 = "Sheet2"
ReDim Arr(1 To 2)
Arr(1) = S1
Arr(2) = S2
Worksheets(Arr).Select



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com



"Karen" wrote in message
...
How do you group worksheets in a macro so I can insert a row in
the same
place in all worksheets? The problem is I will not know the
names nor the
number of worksheets in the file as the user will add
worksheets when needed.

Any and all help will be greatly appreciated.








All times are GMT +1. The time now is 12:03 PM.

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