+ Reply to Thread
Page 3 of 3 FirstFirst 123
Results 31 to 34 of 34

Thread: Extract from multiple worksheets based on one condition and output to new workbook

  1. #31
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    423

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Hi Arlu,

    Yes, that would be great if I could also have the record locked on the exported recordset.

    thank you!

  2. #32
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,376

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    Use this code (updated) -
    Option Explicit
            Dim i As Long
            Dim lrow As Long
    
            Sub report()
    
            Application.DisplayAlerts = False
            Application.ScreenUpdating = False
    
            For i = 1 To 3
                Workbooks.Add
                ActiveWorkbook.SaveAs "Bk" & i
                Workbooks("Bk" & i & ".xlsx").Worksheets(1).Range("A1").Value = "Quarter"
                Workbooks("Bk" & i & ".xlsx").Worksheets(1).Range("B1").Value = "Period"
                Workbooks("Bk" & i & ".xlsx").Worksheets(1).Range("C1").Value = "Status"
                Workbooks("Bk" & i & ".xlsx").Worksheets(1).Range("D1").Value = "Counts"
            Next i
    
            With ThisWorkbook.Worksheets("Master")
                lrow = .Range("A" & Rows.Count).End(xlUp).Row
                For i = 3 To lrow
                    If .Range("A" & i).Value = .Range("F3").Value Or .Range("B" & i).Value = .Range("G3").Value Then
                        .Range("A" & i & ":D" & i).Copy Workbooks("Bk1.xlsx").Worksheets(1).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
                    End If                            
                Next i
                With Workbooks("Bk1.xlsx")
            .Worksheets(1).Cells.EntireColumn.AutoFit
            .Worksheets(1).Cells.Locked = False
            lrow = .Worksheets(1).Range("A" & Rows.Count).End(xlUp).Row
            .Worksheets(1).Range("A1:D" & lrow).Locked = True
            .ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
            .ActiveSheet.EnableSelection = xlUnlockedCells
        End With
                
                lrow = .Range("M" & Rows.Count).End(xlUp).Row
                For i = 3 To lrow
                    If .Range("M" & i).Value = .Range("F3").Value Or .Range("N" & i).Value = .Range("G3").Value Then
                        .Range("M" & i & ":P" & i).Copy Workbooks("Bk2.xlsx").Worksheets(1).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
                    End If
                Next i
                With Workbooks("Bk2.xlsx")
            .Worksheets(1).Cells.EntireColumn.AutoFit
            .Worksheets(1).Cells.Locked = False
            lrow = .Worksheets(1).Range("A" & Rows.Count).End(xlUp).Row
            .Worksheets(1).Range("A1:D" & lrow).Locked = True
            .ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
            .ActiveSheet.EnableSelection = xlUnlockedCells
        End With
             
                lrow = .Range("T" & Rows.Count).End(xlUp).Row
                For i = 3 To lrow
                    If .Range("T" & i).Value = .Range("F3").Value Or .Range("U" & i).Value = .Range("G3").Value Then
                        .Range("T" & i & ":W" & i).Copy Workbooks("Bk3.xlsx").Worksheets(1).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
                    End If
                Next i
    With Workbooks("Bk3.xlsx")
            .Worksheets(1).Cells.EntireColumn.AutoFit
            .Worksheets(1).Cells.Locked = False
            lrow = .Worksheets(1).Range("A" & Rows.Count).End(xlUp).Row
            .Worksheets(1).Range("A1:D" & lrow).Locked = True
            .ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
            .ActiveSheet.EnableSelection = xlUnlockedCells
        End With
            End With
            
            Application.DisplayAlerts = True
            Application.ScreenUpdating = True
    
            End Sub
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #33
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    423

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    A millions of thanks is not enough to express my gratitude.

  4. #34
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    423

    Re: Extract from multiple worksheets based on one condition and output to new workboo

    A millions of thanks is simply not enough to express my gratitude.

+ 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.2.0