+ Reply to Thread
Results 1 to 5 of 5

Applying Macro to only certain sheets

Hybrid View

  1. #1
    Darin Kramer
    Guest

    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. #2
    Jef Gorbach
    Guest

    Re: Applying Macro to only certain sheets


    "Darin Kramer" <darin_kramer@hotmail.com> wrote in message
    news:Oh36#oHuFHA.1032@TK2MSFTNGP12.phx.gbl...
    >
    >
    > 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. #3
    Darin Kramer
    Guest

    Re: Applying Macro to only certain sheets


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


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

  4. #4
    JE McGimpsey
    Guest

    Re: 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 <Oh36#oHuFHA.1032@TK2MSFTNGP12.phx.gbl>,
    Darin Kramer <darin_kramer@hotmail.com> 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. #5
    Jim Thomlinson
    Guest

    RE: 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1