Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default macros and collections

Hi,
I'm running a macro in Excel 2003, which I know need to change to only apply
to specific sheets in my workbook (2 thru 5 of 7). I tried to build a
collection of these sheets and failed. Any ideas on how to apply my macro to
specific sheets, either with or without a building collection, greatly
received.

Regards

Dan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default macros and collections

I use the code below to get every worksheet and then test worksheet name to
determine how I process the sheets. You could name each of the wroksheet the
same 1st 4 letters and then use left(wsname,4) = "good"


Sub test()


For Each ws In Worksheets

wsname = ws.Name

If wsname = "Sheet1" Then

a = 1
End If


Next ws


End Sub

"DanW" wrote:

Hi,
I'm running a macro in Excel 2003, which I know need to change to only apply
to specific sheets in my workbook (2 thru 5 of 7). I tried to build a
collection of these sheets and failed. Any ideas on how to apply my macro to
specific sheets, either with or without a building collection, greatly
received.

Regards

Dan

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default macros and collections

Hi Dan,

Try something like:

'================
Public Sub TesterX()
Dim WB As Workbook
Dim i As Long

Set WB = Workbooks("MyBook.xls") '<<=== CHANGE

For i = 2 To 5
'Do something, e.g.:
MsgBox WB.Sheets(i).Name
Next i

End Sub
'<<================

---
Regards,
Norman


"DanW" wrote in message
...
Hi,
I'm running a macro in Excel 2003, which I know need to change to only
apply
to specific sheets in my workbook (2 thru 5 of 7). I tried to build a
collection of these sheets and failed. Any ideas on how to apply my macro
to
specific sheets, either with or without a building collection, greatly
received.

Regards

Dan



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 340
Default macros and collections

Dan, more than likely you have a macro that works just the way you want it
to do on the active sheet. Let's assume your macro is called "MyMacro" Then

Sub ChangeManySheets()
Worksheets("Sheet1").Select
MyMacro

Worksheets("Sheet4").Select
MyMacro

'and so so forth
End Sub

The above selects a sheet and then runs your macro.

Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel

"DanW" wrote in message
...
Hi,
I'm running a macro in Excel 2003, which I know need to change to only
apply
to specific sheets in my workbook (2 thru 5 of 7). I tried to build a
collection of these sheets and failed. Any ideas on how to apply my macro
to
specific sheets, either with or without a building collection, greatly
received.

Regards

Dan



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default macros and collections

Normally a collection is nore required but sometimes they can be handy. If
you really want collection then here is some sample code...

Public colMySheets As Collection

Sub PopulateCollection()
Dim wks As Worksheet

Set colMySheets = New Collection

colMySheets.Add Sheet1, Sheet1.CodeName
colMySheets.Add Sheet2, Sheet2.CodeName

For Each wks In colMySheets
MsgBox wks.Name
Next wks
End Sub
--
HTH...

Jim Thomlinson


"DanW" wrote:

Hi,
I'm running a macro in Excel 2003, which I know need to change to only apply
to specific sheets in my workbook (2 thru 5 of 7). I tried to build a
collection of these sheets and failed. Any ideas on how to apply my macro to
specific sheets, either with or without a building collection, greatly
received.

Regards

Dan

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
Collections problem Jim Thomlinson Excel Programming 1 June 21st 06 06:21 PM
Collections of Collections David Morton Excel Programming 6 November 13th 04 01:10 AM
Help with collections ksnapp[_45_] Excel Programming 1 April 7th 04 12:42 AM
Using Collections Kerry[_4_] Excel Programming 1 January 25th 04 04:08 PM
Collections Lookups Dave Curtis[_3_] Excel Programming 1 December 3rd 03 09:15 AM


All times are GMT +1. The time now is 11:21 AM.

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

About Us

"It's about Microsoft Excel"