+ Reply to Thread
Results 1 to 3 of 3

VBA code to filter and copy data to new workbook

  1. #1
    Registered User
    Join Date
    06-24-2014
    Location
    Malaysia
    MS-Off Ver
    2007
    Posts
    2

    VBA code to filter and copy data to new workbook

    I created below code to delete unwanted data and copy to new workbook but it took long time. 4000 plus records take me around 30 minutes. I try to create code for filter and copy few sheets to new workbook but failed. Anyone could help to solve my problem?

    Sub RejectionList()

    Dim DataWorkbook
    Dim SaveFileName As String
    Dim ws As Worksheet

    Set DataWorkbook = ActiveWorkbook
    DataWorkbook.Sheets(Array("IT7", "IT2003", "IT2002", "IT2006", "IT2001", "IT2005", "IT2007")).Copy
    Last = Sheets("IT7").Cells(Rows.Count, "H").End(xlUp).Row
    For i = Last To 2 Step -1
    If (Sheets("IT7").Cells(i, "H").Value) = "Reject" Then
    Sheets("IT7").Cells(i, "H").EntireRow.Delete
    End If
    Next i

    Last = Sheets("IT2003").Cells(Rows.Count, "K").End(xlUp).Row
    For i = Last To 2 Step -1
    If (Sheets("IT2003").Cells(i, "K").Value) = "Reject" Then
    Sheets("IT2003").Cells(i, "K").EntireRow.Delete
    End If
    Next i

    Last = Sheets("IT2002").Cells(Rows.Count, "K").End(xlUp).Row
    For i = Last To 2 Step -1
    If (Sheets("IT2002").Cells(i, "K").Value) = "Reject" Then
    Sheets("IT2002").Cells(i, "K").EntireRow.Delete
    End If
    Next i

    Last = Sheets("IT2006").Cells(Rows.Count, "K").End(xlUp).Row
    For i = Last To 2 Step -1
    If (Sheets("IT2006").Cells(i, "K").Value) = "Reject" Then
    Sheets("IT2006").Cells(i, "K").EntireRow.Delete
    End If
    Next i

    Last = Sheets("IT2001").Cells(Rows.Count, "K").End(xlUp).Row
    For i = Last To 2 Step -1
    If (Sheets("IT2001").Cells(i, "K").Value) = "Reject" Then
    Sheets("IT2001").Cells(i, "K").EntireRow.Delete
    End If
    Next i

    Last = Sheets("IT2005").Cells(Rows.Count, "K").End(xlUp).Row
    For i = Last To 2 Step -1
    If (Sheets("IT2005").Cells(i, "K").Value) = "Reject" Then
    Sheets("IT2005").Cells(i, "K").EntireRow.Delete
    End If
    Next i

    Last = Sheets("IT2007").Cells(Rows.Count, "J").End(xlUp).Row
    For i = Last To 2 Step -1
    If (Sheets("IT2007").Cells(i, "J").Value) = "Reject" Then
    Sheets("IT2007").Cells(i, "J").EntireRow.Delete
    End If
    Next i

    Sheets("IT7").Columns("I:Z").Delete
    Sheets("IT2003").Columns("L:Z").Delete
    Sheets("IT2002").Columns("L:Z").Delete
    Sheets("IT2006").Columns("L:Z").Delete
    Sheets("IT2001").Columns("L:Z").Delete
    Sheets("IT2005").Columns("L:Z").Delete
    Sheets("IT2007").Columns("L:Z").Delete
    Application.DisplayAlerts = False

    Application.DisplayAlerts = True
    SaveFileName = DataWorkbook.Path & "\" & Left(DataWorkbook.Name, Len(DataWorkbook.Name) - 8) & ".xlsx"
    ActiveWorkbook.SaveAs Filename:=SaveFileName
    MsgBox "Rejection List To TA Created and Save As" & SaveFileName
    ActiveWorkbook.Close


    End Sub
    Last edited by eunice_hor; 07-31-2014 at 08:31 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-17-2009
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003,excel 2007
    Posts
    678

    Re: VBA code to filter and copy data to new workbook

    when you filter data in a sheet you can just copy the filtered sheet in any other locations

    a sample trivial data in sheet1 is attached. download the file. the macros are already in module in vb editor "test" and "undo"
    run the macro "test". it will copy filtered data in sheet 2


    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    I am not an expert. better solutions may be available
    $$$$venkat1926$$$$@gmail.com

  3. #3
    Registered User
    Join Date
    06-24-2014
    Location
    Malaysia
    MS-Off Ver
    2007
    Posts
    2

    Re: VBA code to filter and copy data to new workbook

    Thanks for your help Venkat.
    Is it possible to copy the filtered data to another new workbook which is not specific workbook?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Code to copy data from a closed workbook and paste in active workbook using named range.
    By paullie1912 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-28-2014, 02:38 AM
  2. VBA Code to filter,Copy and Paste data from one sheet to the other
    By aravindkm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-18-2013, 03:39 PM
  3. Excel VBA filter to criteria and copy data and paste to another workbook
    By aalvaro03 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 11-19-2013, 07:33 PM
  4. Streamline Bulky Code to Filter Data & Copy to Sheets
    By Cowzilla in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-04-2013, 06:54 PM
  5. Macro to filter data and copy to another workbook
    By Roop in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-18-2011, 08:28 PM

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