+ Reply to Thread
Results 1 to 4 of 4

Extracting Data to a different sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    05-03-2017
    Location
    CA
    MS-Off Ver
    210
    Posts
    61

    Extracting Data to a different sheet

    Hi,

    I had a quick question regarding my attached worksheet. As you can see I have 2 line items. I am looking for some sort of VBA code to extract the whole line item into a different worksheet. So for example in the attachment I would like some sort of VBA code that looks into my data and column C "Doc" and if it has information there that starts with "INV" then I want that whole line item extracted to a new worksheet. So this way after the result I will have 2 worksheets. Hopefully I explained that well enough for assistance.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 365
    Posts
    8,029

    Re: Extracting Data to a different sheet

    Try:
    Sub CopyRows()
        Application.ScreenUpdating = False
        Dim LastRow As Long
        LastRow = Sheets("Sheet1").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
        Sheets("Sheet1").Range("A1:U" & LastRow).AutoFilter Field:=3, Criteria1:="=*INV*"
        Sheets("Sheet1").Range("A2:U" & LastRow).SpecialCells(xlCellTypeVisible).EntireRow.Copy
        Worksheets.Add after:=Sheets(Sheets.Count)
        Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial
        If Sheets("Sheet1").AutoFilterMode = True Then Sheets("Sheet1").AutoFilterMode = False
        Application.CutCopyMode = False
        Application.ScreenUpdating = True
    End Sub
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Extracting Data to a different sheet

    Another to try:

    Sub usama(): Dim r As Long, s As Long, ws As Worksheet, wx As Worksheet
            s = 2:  For Each wx In Worksheets
    If wx.Name = "Extract" Then GoTo SetExtract
                    Next: Worksheets.add.Name = "Extract"
    SetExtract: Set wx = Sheets("Extract"): Set ws = Sheets("Sheet1")
            wx.Cells.ClearContents: ws.Rows(1).Copy wx.Cells(1, 1)
            For r = 2 To ws.Range("A" & Rows.count).End(xlUp).Row
                    If Left(ws.Cells(r, 3), 3) = "INV" Then _
                    ws.Rows(r).Copy wx.Cells(s, 1): s = s + 1
            Next r: wx.Columns.AutoFit
    End Sub
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Extracting Data to a different sheet

    Hi usama,

    Thanks for the rep!

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ 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. Replies: 18
    Last Post: 07-08-2017, 11:53 PM
  2. Replies: 0
    Last Post: 08-03-2014, 03:32 AM
  3. Extracting Sum in one sheet with daily data being refreshed in another sheet.
    By Paritosh negi in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 08-03-2013, 07:47 AM
  4. Replies: 5
    Last Post: 07-10-2013, 02:33 PM
  5. Extracting data from a row on one sheet into another sheet based on a unique cell
    By roshanvarghese in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 01-23-2013, 03:49 AM
  6. extracting unknown data from sheet 1 to sheet 2
    By wurugu in forum Excel - New Users/Basics
    Replies: 11
    Last Post: 12-02-2011, 11:58 AM
  7. Extracting Data from One Sheet Using Another
    By ClipperJr4 in forum Excel General
    Replies: 2
    Last Post: 06-29-2008, 07:16 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