+ Reply to Thread
Results 1 to 4 of 4

How do I loop through worksheets

Hybrid View

  1. #1
    Registered User
    Join Date
    04-24-2012
    Location
    San Francisco, USA
    MS-Off Ver
    Excel 2007
    Posts
    60

    How do I loop through worksheets

    I want to loop through 10 worksheets in my workbook (sheet1, sheet2...sheet10) and copy the data from A1 in each sheet and paste into column A in sheets("data"). Sheets("data") is part of the same workbook.

    Many thanks in advance

  2. #2
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: How do I loop through worksheets

    Hi pablowilks,

    Try this:

    Option Explicit
    Sub Macro1()
    
        'Written by Trebor76
        'Visit my website www.excelguru.net.au
    
        Dim wstMySheet As Worksheet
        Dim lngMyRow As Long
        
        Application.ScreenUpdating = False
        
        For Each wstMySheet In ThisWorkbook.Sheets
        
            If wstMySheet.Name <> "data" Then
        
                If lngMyRow = 0 Then
                    lngMyRow = 1 'Initial output row number on the 'data' tab. Change to suit.
                Else
                    lngMyRow = Sheets("data").Cells(Rows.Count, "A").End(xlUp).Row + 1
                End If
                
                Sheets("data").Range("A" & lngMyRow).Value = wstMySheet.Range("A1").Value
            
            End If
        
        Next wstMySheet
        
        Application.ScreenUpdating = True
        
        MsgBox "Process is complete"
    
    End Sub
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  3. #3
    Registered User
    Join Date
    04-24-2012
    Location
    San Francisco, USA
    MS-Off Ver
    Excel 2007
    Posts
    60

    Re: How do I loop through worksheets

    this is great thankyou Robert

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: How do I loop through worksheets

    Thanks for the feedback and you're welcome

+ 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