+ Reply to Thread
Results 1 to 3 of 3

Use VBA to scan and copy rows from worksheets with criteria met to a summary sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    09-27-2010
    Location
    England
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    20

    Exclamation Use VBA to scan and copy rows from worksheets with criteria met to a summary sheet

    Hi I'd like to create a summary sheet for a action logging document which I am currently using.
    This workbook contains numerous sheets with recorded actions some of which are OPEN (when not yet complete) and others are CLOSED (when complete). Until now I'd have to go look through each sheet for OPEN actions.

    I would basically like a script which can scan through all the sheets in the workbook (except one fixed sheet which does not contain actions) , pick out all the actions that are OPEN, copy the rows with OPEN actions to the summary sheet and highlight the sheet name from which the row was copied. New sheets are added each week to the workbook so it continues to grow.

    I've attached a sample file of what I'd like to achieve with more details and requirements.

    Please let me know if you can help or need more info.
    Many thanks.
    Attached Files Attached Files
    Last edited by nuttyengineer; 08-31-2011 at 05:24 PM. Reason: Text update

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Use VBA to scan and copy rows from worksheets with criteria met to a summary shee

    OK Nuttyengineer - here you go.

    The code looks like this
    Option Explicit
    
    Sub CopyOpenToSummary()
    Dim LastRow As Double
    Dim ShtCtr As Double
    Dim RowCtr As Double
    Dim LastShtRow As Double
    
    LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    Range(Cells(4, "A"), Cells(LastRow, "J")).ClearContents
    
    For ShtCtr = 2 To Worksheets.Count
        With Worksheets(ShtCtr)
            LastShtRow = .Cells(Rows.Count, "A").End(xlUp).Row
            For RowCtr = 2 To LastShtRow
                If .Cells(RowCtr, "I") = "OPEN" Then
                    LastRow = Cells(Rows.Count, "A").End(xlUp).Row + 1
                    Cells(LastRow, "A") = Worksheets(ShtCtr).Name
                    .Range(.Cells(RowCtr, "A"), .Cells(RowCtr, "I")).Copy _
                    Destination:=Range(Cells(LastRow, "B"), Cells(LastRow, "J"))
                End If
            Next RowCtr
        End With
    Next ShtCtr
    
    End Sub
    See attached for the test case.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Registered User
    Join Date
    09-27-2010
    Location
    England
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    20

    Smile Re: Use VBA to scan and copy rows from worksheets with criteria met to a summary shee

    MarvinP,

    Thank you very much for your help and clear solution.
    I am trying to teach myself some VBA so this is a good example to learn from.

    This solution will give me a good base to work with and expand.

    Thanks to you I'll mark this one [SOLVED] !!
    Last edited by nuttyengineer; 08-31-2011 at 05:33 PM.

+ 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