Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 397
Default Applying Macro to only certain sheets



Howdie,

My VB currently applies to all sheets in workbook.
I only want it to apply to sheets A, D, E
(Even if I hide sheets b and C) it sitll applies it to them
Can I change the VB below to specify my required sheets as a range, and
then refer to that range somehow...?

VB extract:


For Each sh In ActiveWorkbook.Worksheets
If sh.Name < DestSh.Name Then
Last = Lastrow(DestSh)

sh.Range("b9:p20").Copy DestSh.Cells(Last + 1, "A")

*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Applying Macro to only certain sheets


"Darin Kramer" wrote in message
...


Howdie,

My VB currently applies to all sheets in workbook.
I only want it to apply to sheets A, D, E
(Even if I hide sheets b and C) it sitll applies it to them
Can I change the VB below to specify my required sheets as a range, and
then refer to that range somehow...?

VB extract:


For Each sh In ActiveWorkbook.Worksheets
If sh.Name < DestSh.Name Then
Last = Lastrow(DestSh)

sh.Range("b9:p20").Copy DestSh.Cells(Last + 1, "A")

*** Sent via Developersdex http://www.developersdex.com ***


For Each Sh In Worksheets(Array("A", "B", "C"))


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 397
Default Applying Macro to only certain sheets


Thank you so so so so much!!!!!


*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Applying Macro to only certain sheets

One way:

Dim ws As Worksheet
For Each ws In Worksheets
If ws.Name Like "[ADE]" Then
'do stuff
End If
Next ws


In article ,
Darin Kramer wrote:

Howdie,

My VB currently applies to all sheets in workbook.
I only want it to apply to sheets A, D, E
(Even if I hide sheets b and C) it sitll applies it to them
Can I change the VB below to specify my required sheets as a range, and
then refer to that range somehow...?

VB extract:


For Each sh In ActiveWorkbook.Worksheets
If sh.Name < DestSh.Name Then
Last = Lastrow(DestSh)

sh.Range("b9:p20").Copy DestSh.Cells(Last + 1, "A")

*** Sent via Developersdex http://www.developersdex.com ***

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,119
Default Applying Macro to only certain sheets

You can create a collection of worksheets and then traverse the collection
something like this

Public MySheets As Collection

Sub AddSheets()
Set MySheets = New Collection
MySheets.Add Sheet1, Sheet1.Name
MySheets.Add Sheet2, Sheet2.Name

End Sub

Sub Test()
Dim wks As Worksheet

Call AddSheets
For Each wks In MySheets
MsgBox wks.Name
Next wks

End Sub

--
HTH...

Jim Thomlinson


"Darin Kramer" wrote:



Howdie,

My VB currently applies to all sheets in workbook.
I only want it to apply to sheets A, D, E
(Even if I hide sheets b and C) it sitll applies it to them
Can I change the VB below to specify my required sheets as a range, and
then refer to that range somehow...?

VB extract:


For Each sh In ActiveWorkbook.Worksheets
If sh.Name < DestSh.Name Then
Last = Lastrow(DestSh)

sh.Range("b9:p20").Copy DestSh.Cells(Last + 1, "A")

*** Sent via Developersdex http://www.developersdex.com ***



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
applying COUNTIF formula across several sheets belvy123 Excel Discussion (Misc queries) 4 September 30th 08 09:03 AM
applying formulas for all sheets selected emilr17 Excel Worksheet Functions 3 July 16th 08 06:46 PM
Applying J-Walk's SheetOffset() to SUM across sheets - possible? Shirish Excel Worksheet Functions 3 November 8th 06 10:27 AM
Applying Protection To Multiple Sheets Mhz New Users to Excel 4 July 6th 06 01:22 PM
applying rules to Excel Sheets using Macros [email protected] Excel Programming 1 May 11th 05 02:21 PM


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