#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 53
Default Tab Names in Macro

I have a macro set up that selects each worksheet and transfers data to each
one. The macro selects the worksheet by name, so if I change a worksheet
name, the macro will not run.

I don't know much about arrays or dim'ing but I know this can be done.

What I would really, really like is a macro to name all worksheets from a
list on one worksheet. Then I would like to run another macro to transfer
the data to each sheet no matter what the sheet tab is named.

I hope I made this clear enough!

Thanks,
Cheri
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Tab Names in Macro

If you're really updating all the worksheets in a workbook, you can loop through
them without knowing their names.

dim Wks as worksheet
for each wks in activeworkbook.worksheets
'code to do the work against wks here
next wks



Cheri wrote:

I have a macro set up that selects each worksheet and transfers data to each
one. The macro selects the worksheet by name, so if I change a worksheet
name, the macro will not run.

I don't know much about arrays or dim'ing but I know this can be done.

What I would really, really like is a macro to name all worksheets from a
list on one worksheet. Then I would like to run another macro to transfer
the data to each sheet no matter what the sheet tab is named.

I hope I made this clear enough!

Thanks,
Cheri


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Tab Names in Macro

Several ways to go about this.

In your code don't address the sheets by name or position.

Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
'do your tranfer stuff
Next ws

If you did want to rename all the sheets(not necessary if code above used) this
macro can do it.

Sub NameWS()
'name sheets from a unique list in Column A on first sheet
On Error Resume Next
For i = 1 To Worksheets.Count
Sheets(i).Name = Sheets(1).Cells(i, 1).Value
Next i
End Sub


Gord Dibben MS Excel MVP

On Thu, 28 Jun 2007 14:44:02 -0700, Cheri
wrote:

I have a macro set up that selects each worksheet and transfers data to each
one. The macro selects the worksheet by name, so if I change a worksheet
name, the macro will not run.

I don't know much about arrays or dim'ing but I know this can be done.

What I would really, really like is a macro to name all worksheets from a
list on one worksheet. Then I would like to run another macro to transfer
the data to each sheet no matter what the sheet tab is named.

I hope I made this clear enough!

Thanks,
Cheri


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 53
Default Tab Names in Macro

Okay, adding on what I was doing since this did not work for me. My macro
selects the "Stats" worksheet and copies a range. It then selects a number
of tabs (can be different amounts depending on data copied). So, I may
select tabs 3-10 one time and 3-16 tabs another time depending on how many
tabs are in the particular workbook. (Tabs 1 and 2 would never be selected).
This way, I can copy the data to all subsequent sheets at one time. Is this
possible, or do I have to do each tab separately, using your code?

I appreciate your help!!!

"Cheri" wrote:

I have a macro set up that selects each worksheet and transfers data to each
one. The macro selects the worksheet by name, so if I change a worksheet
name, the macro will not run.

I don't know much about arrays or dim'ing but I know this can be done.

What I would really, really like is a macro to name all worksheets from a
list on one worksheet. Then I would like to run another macro to transfer
the data to each sheet no matter what the sheet tab is named.

I hope I made this clear enough!

Thanks,
Cheri

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 53
Default Tab Names in Macro

Thanks Dave! I am wondering how I would do this without selecting tabs 1 and
2 as these would never be included in the transfer (since the data is
transfering from one of them)

I appreciate you help! Thanks!!

"Dave Peterson" wrote:

If you're really updating all the worksheets in a workbook, you can loop through
them without knowing their names.

dim Wks as worksheet
for each wks in activeworkbook.worksheets
'code to do the work against wks here
next wks



Cheri wrote:

I have a macro set up that selects each worksheet and transfers data to each
one. The macro selects the worksheet by name, so if I change a worksheet
name, the macro will not run.

I don't know much about arrays or dim'ing but I know this can be done.

What I would really, really like is a macro to name all worksheets from a
list on one worksheet. Then I would like to run another macro to transfer
the data to each sheet no matter what the sheet tab is named.

I hope I made this clear enough!

Thanks,
Cheri


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 53
Default Tab Names in Macro

Geesh...I put my reply the wrong place :o)

Okay, adding on what I was doing since this did not work for me. My macro
selects the "Stats" worksheet and copies a range. It then selects a number
of tabs (can be different amounts depending on data copied). So, I may
select tabs 3-10 one time and 3-16 tabs another time depending on how many
tabs are in the particular workbook. (Tabs 1 and 2 would never be selected).
This way, I can copy the data to all subsequent sheets at one time. Is this
possible, or do I have to do each tab separately, using your code?

I appreciate your help!!!


"Gord Dibben" wrote:

Several ways to go about this.

In your code don't address the sheets by name or position.

Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
'do your tranfer stuff
Next ws

If you did want to rename all the sheets(not necessary if code above used) this
macro can do it.

Sub NameWS()
'name sheets from a unique list in Column A on first sheet
On Error Resume Next
For i = 1 To Worksheets.Count
Sheets(i).Name = Sheets(1).Cells(i, 1).Value
Next i
End Sub


Gord Dibben MS Excel MVP

On Thu, 28 Jun 2007 14:44:02 -0700, Cheri
wrote:

I have a macro set up that selects each worksheet and transfers data to each
one. The macro selects the worksheet by name, so if I change a worksheet
name, the macro will not run.

I don't know much about arrays or dim'ing but I know this can be done.

What I would really, really like is a macro to name all worksheets from a
list on one worksheet. Then I would like to run another macro to transfer
the data to each sheet no matter what the sheet tab is named.

I hope I made this clear enough!

Thanks,
Cheri



  #7   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Tab Names in Macro

If you pre-select the sheets you need using CTRL + click you could change the
code to

Dim ws a s Worksheet
For Each ws In ActiveWindow.SelectedSheets
'transfer stuff
Next ws

Otherwise you would have to build an array of sheets based on some criteria.


Gord


On Thu, 28 Jun 2007 15:50:00 -0700, Cheri
wrote:

Geesh...I put my reply the wrong place :o)

Okay, adding on what I was doing since this did not work for me. My macro
selects the "Stats" worksheet and copies a range. It then selects a number
of tabs (can be different amounts depending on data copied). So, I may
select tabs 3-10 one time and 3-16 tabs another time depending on how many
tabs are in the particular workbook. (Tabs 1 and 2 would never be selected).
This way, I can copy the data to all subsequent sheets at one time. Is this
possible, or do I have to do each tab separately, using your code?

I appreciate your help!!!


"Gord Dibben" wrote:

Several ways to go about this.

In your code don't address the sheets by name or position.

Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
'do your tranfer stuff
Next ws

If you did want to rename all the sheets(not necessary if code above used) this
macro can do it.

Sub NameWS()
'name sheets from a unique list in Column A on first sheet
On Error Resume Next
For i = 1 To Worksheets.Count
Sheets(i).Name = Sheets(1).Cells(i, 1).Value
Next i
End Sub


Gord Dibben MS Excel MVP

On Thu, 28 Jun 2007 14:44:02 -0700, Cheri
wrote:

I have a macro set up that selects each worksheet and transfers data to each
one. The macro selects the worksheet by name, so if I change a worksheet
name, the macro will not run.

I don't know much about arrays or dim'ing but I know this can be done.

What I would really, really like is a macro to name all worksheets from a
list on one worksheet. Then I would like to run another macro to transfer
the data to each sheet no matter what the sheet tab is named.

I hope I made this clear enough!

Thanks,
Cheri




  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 53
Default Tab Names in Macro

Okay, that is fine. I will just use the code you gave me and let it paste to
each sheet, one at a time. Now, how should your code read so that sheets 1
and 2 are not selected?

Thanks again!

"Gord Dibben" wrote:

If you pre-select the sheets you need using CTRL + click you could change the
code to

Dim ws a s Worksheet
For Each ws In ActiveWindow.SelectedSheets
'transfer stuff
Next ws

Otherwise you would have to build an array of sheets based on some criteria.


Gord


On Thu, 28 Jun 2007 15:50:00 -0700, Cheri
wrote:

Geesh...I put my reply the wrong place :o)

Okay, adding on what I was doing since this did not work for me. My macro
selects the "Stats" worksheet and copies a range. It then selects a number
of tabs (can be different amounts depending on data copied). So, I may
select tabs 3-10 one time and 3-16 tabs another time depending on how many
tabs are in the particular workbook. (Tabs 1 and 2 would never be selected).
This way, I can copy the data to all subsequent sheets at one time. Is this
possible, or do I have to do each tab separately, using your code?

I appreciate your help!!!


"Gord Dibben" wrote:

Several ways to go about this.

In your code don't address the sheets by name or position.

Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
'do your tranfer stuff
Next ws

If you did want to rename all the sheets(not necessary if code above used) this
macro can do it.

Sub NameWS()
'name sheets from a unique list in Column A on first sheet
On Error Resume Next
For i = 1 To Worksheets.Count
Sheets(i).Name = Sheets(1).Cells(i, 1).Value
Next i
End Sub


Gord Dibben MS Excel MVP

On Thu, 28 Jun 2007 14:44:02 -0700, Cheri
wrote:

I have a macro set up that selects each worksheet and transfers data to each
one. The macro selects the worksheet by name, so if I change a worksheet
name, the macro will not run.

I don't know much about arrays or dim'ing but I know this can be done.

What I would really, really like is a macro to name all worksheets from a
list on one worksheet. Then I would like to run another macro to transfer
the data to each sheet no matter what the sheet tab is named.

I hope I made this clear enough!

Thanks,
Cheri




  #9   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Tab Names in Macro

The code depends on what you worksheets you've grouped. So if you don't include
sheets 1 and 2 in that grouping, then you'll be fine.

If sheets 1 and 2 are always the left most worksheets, you can click on the
third tab and shiftclick on the rightmost.



Cheri wrote:

Okay, that is fine. I will just use the code you gave me and let it paste to
each sheet, one at a time. Now, how should your code read so that sheets 1
and 2 are not selected?

Thanks again!

"Gord Dibben" wrote:

If you pre-select the sheets you need using CTRL + click you could change the
code to

Dim ws a s Worksheet
For Each ws In ActiveWindow.SelectedSheets
'transfer stuff
Next ws

Otherwise you would have to build an array of sheets based on some criteria.


Gord


On Thu, 28 Jun 2007 15:50:00 -0700, Cheri
wrote:

Geesh...I put my reply the wrong place :o)

Okay, adding on what I was doing since this did not work for me. My macro
selects the "Stats" worksheet and copies a range. It then selects a number
of tabs (can be different amounts depending on data copied). So, I may
select tabs 3-10 one time and 3-16 tabs another time depending on how many
tabs are in the particular workbook. (Tabs 1 and 2 would never be selected).
This way, I can copy the data to all subsequent sheets at one time. Is this
possible, or do I have to do each tab separately, using your code?

I appreciate your help!!!


"Gord Dibben" wrote:

Several ways to go about this.

In your code don't address the sheets by name or position.

Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
'do your tranfer stuff
Next ws

If you did want to rename all the sheets(not necessary if code above used) this
macro can do it.

Sub NameWS()
'name sheets from a unique list in Column A on first sheet
On Error Resume Next
For i = 1 To Worksheets.Count
Sheets(i).Name = Sheets(1).Cells(i, 1).Value
Next i
End Sub


Gord Dibben MS Excel MVP

On Thu, 28 Jun 2007 14:44:02 -0700, Cheri
wrote:

I have a macro set up that selects each worksheet and transfers data to each
one. The macro selects the worksheet by name, so if I change a worksheet
name, the macro will not run.

I don't know much about arrays or dim'ing but I know this can be done.

What I would really, really like is a macro to name all worksheets from a
list on one worksheet. Then I would like to run another macro to transfer
the data to each sheet no matter what the sheet tab is named.

I hope I made this clear enough!

Thanks,
Cheri





--

Dave Peterson
  #10   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,355
Default Tab Names in Macro

You could change the worksheet codename for Sheet 1 and 2 and test for that.
To change the code name, do the following

F11 from the workbook
Ctrl R to show the VBAProject
Select the worksheet for SHeet1
Press F4 to get the properties window
You should see something that looks like (NAME) with Sheet1 or something
similar in it.
Replace SHeet1 with a worksheet code name.
Do the same for your Sheet 2

I'm going to assume you've called them "MySheet1" and "MySheet2" for this
example.

Dim WS as worksheet

for each ws in ThisWorkbook.worksheets
if not ws.codename = "mySheet1" and _
not ws.codename = "mySheet2" then
'perform the actions on your sheets.
end if
next ws

HTH,
Barb Reinhardt
"Cheri" wrote:

Okay, that is fine. I will just use the code you gave me and let it paste to
each sheet, one at a time. Now, how should your code read so that sheets 1
and 2 are not selected?

Thanks again!

"Gord Dibben" wrote:

If you pre-select the sheets you need using CTRL + click you could change the
code to

Dim ws a s Worksheet
For Each ws In ActiveWindow.SelectedSheets
'transfer stuff
Next ws

Otherwise you would have to build an array of sheets based on some criteria.


Gord


On Thu, 28 Jun 2007 15:50:00 -0700, Cheri
wrote:

Geesh...I put my reply the wrong place :o)

Okay, adding on what I was doing since this did not work for me. My macro
selects the "Stats" worksheet and copies a range. It then selects a number
of tabs (can be different amounts depending on data copied). So, I may
select tabs 3-10 one time and 3-16 tabs another time depending on how many
tabs are in the particular workbook. (Tabs 1 and 2 would never be selected).
This way, I can copy the data to all subsequent sheets at one time. Is this
possible, or do I have to do each tab separately, using your code?

I appreciate your help!!!


"Gord Dibben" wrote:

Several ways to go about this.

In your code don't address the sheets by name or position.

Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
'do your tranfer stuff
Next ws

If you did want to rename all the sheets(not necessary if code above used) this
macro can do it.

Sub NameWS()
'name sheets from a unique list in Column A on first sheet
On Error Resume Next
For i = 1 To Worksheets.Count
Sheets(i).Name = Sheets(1).Cells(i, 1).Value
Next i
End Sub


Gord Dibben MS Excel MVP

On Thu, 28 Jun 2007 14:44:02 -0700, Cheri
wrote:

I have a macro set up that selects each worksheet and transfers data to each
one. The macro selects the worksheet by name, so if I change a worksheet
name, the macro will not run.

I don't know much about arrays or dim'ing but I know this can be done.

What I would really, really like is a macro to name all worksheets from a
list on one worksheet. Then I would like to run another macro to transfer
the data to each sheet no matter what the sheet tab is named.

I hope I made this clear enough!

Thanks,
Cheri






  #11   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Tab Names in Macro

If you know the worksheets that should be avoided (by name), you can use:

dim wks as worksheet
for each wks in activeworkbook.worksheets
select case lcase(wks.name)
case is = "sheet1", "sheet2"
'do nothing
case else
'your code here
end select
next wks

If you don't always know the name, but the sheets are always the two leftmost
sheets:

dim wCtr as long
for wctr = 3 to activeworkbook.worksheets.count
'code to do the work agains worksheets(wctr)
next wctr

Cheri wrote:

Thanks Dave! I am wondering how I would do this without selecting tabs 1 and
2 as these would never be included in the transfer (since the data is
transfering from one of them)

I appreciate you help! Thanks!!

"Dave Peterson" wrote:

If you're really updating all the worksheets in a workbook, you can loop through
them without knowing their names.

dim Wks as worksheet
for each wks in activeworkbook.worksheets
'code to do the work against wks here
next wks



Cheri wrote:

I have a macro set up that selects each worksheet and transfers data to each
one. The macro selects the worksheet by name, so if I change a worksheet
name, the macro will not run.

I don't know much about arrays or dim'ing but I know this can be done.

What I would really, really like is a macro to name all worksheets from a
list on one worksheet. Then I would like to run another macro to transfer
the data to each sheet no matter what the sheet tab is named.

I hope I made this clear enough!

Thanks,
Cheri


--

Dave Peterson


--

Dave Peterson
  #12   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default Tab Names in Macro

ActiveWindow.SelectedSheets runs only on those you pre-selected. Just don't
select sheet1 and 2 or the "Stats" sheet.

You say the macro you currently have selects a variable number of sheets based
upon amount of data to be transferred and/or the number of sheets in a workbook.

How does your macro do that?

Post the code you have now.


Gord

On Thu, 28 Jun 2007 16:22:02 -0700, Cheri
wrote:

Okay, that is fine. I will just use the code you gave me and let it paste to
each sheet, one at a time. Now, how should your code read so that sheets 1
and 2 are not selected?

Thanks again!

"Gord Dibben" wrote:

If you pre-select the sheets you need using CTRL + click you could change the
code to

Dim ws a s Worksheet
For Each ws In ActiveWindow.SelectedSheets
'transfer stuff
Next ws

Otherwise you would have to build an array of sheets based on some criteria.


Gord


On Thu, 28 Jun 2007 15:50:00 -0700, Cheri
wrote:

Geesh...I put my reply the wrong place :o)

Okay, adding on what I was doing since this did not work for me. My macro
selects the "Stats" worksheet and copies a range. It then selects a number
of tabs (can be different amounts depending on data copied). So, I may
select tabs 3-10 one time and 3-16 tabs another time depending on how many
tabs are in the particular workbook. (Tabs 1 and 2 would never be selected).
This way, I can copy the data to all subsequent sheets at one time. Is this
possible, or do I have to do each tab separately, using your code?

I appreciate your help!!!


"Gord Dibben" wrote:

Several ways to go about this.

In your code don't address the sheets by name or position.

Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
'do your tranfer stuff
Next ws

If you did want to rename all the sheets(not necessary if code above used) this
macro can do it.

Sub NameWS()
'name sheets from a unique list in Column A on first sheet
On Error Resume Next
For i = 1 To Worksheets.Count
Sheets(i).Name = Sheets(1).Cells(i, 1).Value
Next i
End Sub


Gord Dibben MS Excel MVP

On Thu, 28 Jun 2007 14:44:02 -0700, Cheri
wrote:

I have a macro set up that selects each worksheet and transfers data to each
one. The macro selects the worksheet by name, so if I change a worksheet
name, the macro will not run.

I don't know much about arrays or dim'ing but I know this can be done.

What I would really, really like is a macro to name all worksheets from a
list on one worksheet. Then I would like to run another macro to transfer
the data to each sheet no matter what the sheet tab is named.

I hope I made this clear enough!

Thanks,
Cheri





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
unable to delete Macro names George P Excel Discussion (Misc queries) 1 January 28th 07 10:17 PM
Macro to capture worksheet names El Bee Excel Worksheet Functions 2 July 13th 06 05:56 PM
Increase number of macro names Richard F. Excel Worksheet Functions 1 October 20th 05 04:04 PM
macro to change numbers to names WAB Excel Worksheet Functions 3 April 16th 05 02:14 PM
Macro names Natalie Excel Discussion (Misc queries) 1 March 5th 05 11:53 AM


All times are GMT +1. The time now is 05: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"