+ Reply to Thread
Results 1 to 5 of 5

Copy paste values to another workbook based on multiple cell values

Hybrid View

  1. #1
    Registered User
    Join Date
    07-17-2012
    Location
    Nederland
    MS-Off Ver
    Excel 2010
    Posts
    14

    Copy paste values to another workbook based on multiple cell values

    Hi All,

    I have some basic understanding of VBA, but I cannot find a proper solution for the following:

    I have a dataset with a lot of entries, which is still growing. In order to have a better overview of several specific items, I would like to export (copy paste values) the information of each row to another sheet when it matches multiple cell values. The cell values are the date, a category and a specification.

    In the attachment I included a sample workbook.

    Hope you guys can help me with this problem.

    Thanks in advance!
    Attached Files Attached Files
    Last edited by Bazinga; 12-17-2014 at 10:57 PM.

  2. #2
    Registered User
    Join Date
    07-17-2012
    Location
    Nederland
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Copy paste values to another workbook based on multiple cell values

    anyone?

  3. #3
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Copy paste values to another workbook based on multiple cell values

    Hi Bazinga

    Try this Code in the attached. There are two Buttons, "1 Create Lists" and "2 Extract Stuff".

    "1 Create Lists" needs clicked initially. It will then need be clicked any time you add Data to the Worksheet.

    "2 Extract Stuff" does all of this
    I would like to export (copy paste values) the information of each row to another sheet when it matches multiple cell values. The cell values are the date, a category and a specification.
    Option Explicit
    
    Sub Button3_Click()
      Dim LR As Long
      Range("K:M").ClearContents
    
      LR = Cells.Find("*", Cells(Rows.Count, Columns.Count), SearchOrder:=xlByRows, _
          SearchDirection:=xlPrevious).Row
      Range("B5:B" & LR).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _
          "K5"), Unique:=True
      ActiveWorkbook.Names.Add Name:="Date", RefersTo:= _
          "=OFFSET(Input!$K$6,0,0,(COUNTA(Input!$K:$K)-1),1)"
      Range("C5:C" & LR).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _
          "L5"), Unique:=True
      ActiveWorkbook.Names.Add Name:="Category", RefersTo:= _
          "=OFFSET(Input!$L$6,0,0,(COUNTA(Input!$L:$L)-1),1)"
      Range("D5:D" & LR).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=Range( _
          "M5"), Unique:=True
      ActiveWorkbook.Names.Add Name:="Spec", RefersTo:= _
          "=OFFSET(Input!$M$6,0,0,(COUNTA(Input!$M:$M)-1),1)"
    
    End Sub
    
    
    
    Sub Button5_Click()
      Dim LR As Long
      Dim wsSrc As Worksheet, wsTgt As Worksheet
      
      Set wsSrc = ActiveSheet
      Set wsTgt = Sheets("Output")
      
      Application.ScreenUpdating = False
      With wsTgt
      .Cells.ClearContents
      End With
    
    With wsSrc
      LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
          SearchDirection:=xlPrevious).Row
      If .AutoFilterMode Then
        .Range("B5").AutoFilter
      End If
      .Range("B5:G" & LR).AutoFilter Field:=1, Criteria1:="=" & .Range("J5").Text & ""
      .Range("B5:G" & LR).AutoFilter Field:=2, Criteria1:="=" & .Range("J6").Text & ""
      .Range("B5:G" & LR).AutoFilter Field:=3, Criteria1:="=" & .Range("J7").Text & ""
      .Range(.Cells(5, 2), .Cells(LR, "G")).SpecialCells(xlCellTypeVisible).Copy
      wsTgt.Range("A1").PasteSpecial (xlPasteColumnWidths)
      wsTgt.Range("A1").PasteSpecial (xlPasteValues)
      wsTgt.Range("A1").PasteSpecial (xlPasteFormats)
      .AutoFilterMode = False
      End With
      Application.CutCopyMode = False
      Application.ScreenUpdating = True
      wsTgt.Activate
    End Sub
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  4. #4
    Registered User
    Join Date
    07-17-2012
    Location
    Nederland
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Copy paste values to another workbook based on multiple cell values

    Thanks! Works great

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Copy paste values to another workbook based on multiple cell values

    You're welcome...glad I could help. Thanks for the Rep.

+ 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] Open multiple workbooks based on cell values and copy and paste information
    By egemencoskun in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-24-2014, 04:37 AM
  2. Copy/paste values from multiple selection into new workbook
    By gigi85 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-31-2014, 10:37 AM
  3. Copy and Paste columns based on cell values
    By devin1428 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-17-2012, 07:50 AM
  4. copy/paste multiple values based on time/date stamp
    By qwerty1945 in forum Excel General
    Replies: 4
    Last Post: 02-18-2012, 04:20 PM
  5. Copy and Paste values based on another cell
    By clc3 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-14-2012, 05:15 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