Consulting

Results 1 to 6 of 6

Thread: Solved: Copy/paste from all worksheets, except sheet1

  1. #1
    VBAX Regular
    Joined
    Aug 2007
    Posts
    21
    Location

    Solved: Copy/paste from all worksheets, except sheet1

    I need to do several activities on all worksheets in a workbook, except for sheet1.

    The code so far is as follows:

    Sub PerformActivities ()

    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets

    ?I deleted the copy/pasting code here in order to decrease the length of this post

    Next ws

    End Sub


    What happens is that information from several worksheets is collected and copied to sheet1. Therefore the process should not collect information from sheet1 in order not to mess up that sheet. Now I am trying to figure out how to make it look through all worksheets except sheet1 (this is also the name of the sheet). Any suggestions?

  2. #2
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    You can use:
    [VBA] If Not (ws Is Sheet1) Then
    [/VBA]
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    VBAX Regular
    Joined
    Aug 2007
    Posts
    21
    Location
    Thanks for your reply Rory, the code is:

    Sub PerformActivities()
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
    If Not (ws Is Sheet1) Then
    Range("A1") = 1000 'Replaced my code with this line
    End If
    Next ws
    End Sub

    For some reason the macro does not go to the next worksheet (even though it says next ws). Any idea why is that?

  4. #4
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    You need to specify that the Range belongs to ws:
    [VBA]Sub PerformActivities()
    Dim ws As Worksheet
    For Each ws In ThisWorkbook.Worksheets
    If Not (ws Is Sheet1) Then
    ws.Range("A1") = 1000 'Replaced my code with this line
    End If
    Next ws
    End Sub[/VBA]
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    VBAX Regular
    Joined
    Aug 2007
    Posts
    21
    Location
    it works, thanks so much. I see that I still need to learn a lot..

  6. #6
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    No problem. Unless you specify otherwise, the Range and Cells properties refer to the active sheet (or, if they are in the module behind a worksheet, they default to that worksheet).
    Regards,
    Rory

    Microsoft MVP - Excel

Posting Permissions

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