+ Reply to Thread
Results 1 to 8 of 8

Thread: Macro to Filter & Extract Data to a New Workbook

  1. #1
    Registered User
    Join Date
    06-09-2011
    Location
    EU
    MS-Off Ver
    Excel 2007
    Posts
    4

    Macro to Filter & Extract Data to a New Workbook

    Hi everyone,
    I'm stuck here, trying to write a macro that would filter data out of active worksheet and extract it into a new workbook. Please view attached file for reference.

    I need the macro to filter the data in Activesheet (which would be protected except for column C) and extract each row in which there's a record of items being sold (C<>B; D>0; F>0). The data in column C would be entered manually.

    Also it would be nice if at the same time the macro could copy entire column C and paste it into column B on sheet Stock (which would be hidden) so that the Items Left would represent new amounts of Items in stock. Anyway. this second feature is not of a top priority

    Thank you for your time, friends.
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    Japan
    MS-Off Ver
    Excel 2010
    Posts
    779

    Re: Macro to Filter & Extract Data to a New Workbook

    I don't follow, what data are you trying to extract?
    If you are happy with the answer, please click the Star icon in the below left hand corner.

    Good sites to start learning.

    snb's VBA Help Files
    Jerry Beaucaires Excel Assistant
    J & R Excel Consultancy Services

    How to post code correctly: Correct Code Posting

  3. #3
    Registered User
    Join Date
    06-09-2011
    Location
    EU
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Macro to Filter & Extract Data to a New Workbook

    All of those rows from Activesheet in which there's a record in column C (and C does not equal B) i.e. I need a list of all items that were sold.

  4. #4
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Macro to Filter & Extract Data to a New Workbook

    You can use autofilter or advancedfilter.



  5. #5
    Registered User
    Join Date
    06-09-2011
    Location
    EU
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Macro to Filter & Extract Data to a New Workbook

    Quote Originally Posted by snb View Post
    You can use autofilter or advancedfilter.
    That doesn't help at all since the workbook will be used by people who don't do copy&paste let alone advanced filter.

  6. #6
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Macro to Filter & Extract Data to a New Workbook

    You can use either method in a macro, so the user only has to click a button etc.



  7. #7
    Registered User
    Join Date
    06-09-2011
    Location
    EU
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Macro to Filter & Extract Data to a New Workbook

    Easy enough, mate

  8. #8
    Valued Forum Contributor JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    Japan
    MS-Off Ver
    Excel 2010
    Posts
    779

    Re: Macro to Filter & Extract Data to a New Workbook

    Not exactly sure this is what you are after, but here is the code anyway.

    Code:

    Dim ws As Worksheet
        Dim LR As Long
        Dim ws1 As Worksheet
        Dim i As Long
        Dim Wk As Workbook
        Dim j As Long
           Application.ScreenUpdating = False
                Set ws = Worksheets("Activesheet")
                Set ws1 = Worksheets("Stock")
                Set Wk1 = Workbooks.Add()
                     LR = ws.Cells(ws.Rows.Count, 2).End(xlUp).Row
                 j = 2
                     For i = 2 To LR
                       If ws.Range("C" & i).Value <> "" Then
                            Wk1.Worksheets("Sheet1").Range("A" & j).Resize(, 7).Value = ws.Range("A" & i).Resize(, 7).Value
                        j = j + 1
                       End If
                     Next i
                     With Wk1
                          .Worksheets("Sheet1").Range("A1:G1") = ws.Range("A1:G1").Value
                          .Worksheets("Sheet1").Range("A1:G1").EntireColumn.AutoFit
                     End With
                     Wk1.Worksheets("Sheet1").Range("A1:G1").Select
                     With Selection.Borders
                       .LineStyle = xlContinuous
                       .Weight = xlThin
                       .ColorIndex = xlAutomatic
                     End With
                     With Selection.Interior
                        .Pattern = xlSolid
                        .PatternColorIndex = xlAutomatic
                        .Color = 13434879
                        .TintAndShade = 0
                        .PatternTintAndShade = 0
                     End With
                 ws1.Visible = True
                     ws1.Range("B2:B" & LR).Value = ws.Range("C2:C" & LR).Value
                 ws1.Visible = False
                Wk1.SaveAs "C:\Users\Owner\Desktop\YourFileName.xlsx", FileFormat:=51
            Application.ScreenUpdating = True
    End Sub
    Cheers
    If you are happy with the answer, please click the Star icon in the below left hand corner.

    Good sites to start learning.

    snb's VBA Help Files
    Jerry Beaucaires Excel Assistant
    J & R Excel Consultancy Services

    How to post code correctly: Correct Code Posting

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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