+ Reply to Thread
Results 1 to 3 of 3

Copy and paste data to separate sheets based on mutiple criteria

Hybrid View

Ricker090 Copy and paste data to... 04-21-2011, 02:43 PM
tigeravatar Re: Copy and paste data to... 04-21-2011, 03:19 PM
Ricker090 Re: Copy and paste data to... 04-21-2011, 03:48 PM
  1. #1
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    157

    Copy and paste data to separate sheets based on mutiple criteria

    I have a spreadsheet that has a master data page. The data is sorted into separate columns. I would like a macro that copies and pastes the data into their respective worksheets.

    I have attached a sample.

    As always, any help is greatly appreciated.
    Attached Files Attached Files
    Last edited by Ricker090; 04-21-2011 at 07:24 PM.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Copy and paste data to separate sheets based on mutiple criteria

    Ricker090,

    Something like this?

    Sub MoveData()
    
        Application.ScreenUpdating = False
        Application.Calculation = xlCalculationManual
        
        Dim ws As Worksheet, wsDest As Worksheet, wsData As Worksheet: Set wsData = Sheets("Master DATA")
        Dim DataTitle As String, wsFound As Boolean, iCell As Range
        
        Dim LastItem As Long:       LastItem = Sheets("Master DATA").Range("A" & Rows.Count).End(xlUp).Row
        Dim CurrentItem As Long:    CurrentItem = 2
        While CurrentItem <= LastItem
            
            DataTitle = wsData.Range("A" & CurrentItem).Value & wsData.Range("B" & CurrentItem).Value & wsData.Range("C" & CurrentItem).Value
            wsFound = False
            For Each ws In ThisWorkbook.Sheets
                If ws.Name = DataTitle Then
                    Set wsDest = ws
                    wsFound = True
                    Exit For
                End If
            Next ws
            
            If wsFound = False Then
                Application.CutCopyMode = False
                wsData.Range("A1:E1").Copy
                Set wsDest = Sheets.Add(after:=Sheets(Sheets.Count))
                wsDest.Name = DataTitle
                wsDest.Range("A1").PasteSpecial xlPasteAll
                wsDest.Range("A1").PasteSpecial Paste:=xlPasteColumnWidths
            End If
            
            For Each iCell In wsData.Range("A" & CurrentItem & ":E" & CurrentItem)
                Dim rngNextLine As Range:   Set rngNextLine = wsDest.Cells(Rows.Count, iCell.Column).End(xlUp).Offset(1, 0)
                rngNextLine.Value = iCell.Value
            Next iCell
            
            CurrentItem = CurrentItem + 1
        Wend
        
        Application.Calculation = xlCalculationAutomatic
        Application.ScreenUpdating = True
        
    End Sub


    Hope that helps,
    ~tigeravatar

  3. #3
    Forum Contributor
    Join Date
    06-17-2010
    Location
    Dallas, TX
    MS-Off Ver
    Excel 2010
    Posts
    157

    Re: Copy and paste data to separate sheets based on mutiple criteria

    That works great. Thanks!

    It's interesting though. The code appears to be more complex that I had initially anticipated.

+ 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.6.0 RC 1