+ Reply to Thread
Results 1 to 6 of 6

Copy data from multiple sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    09-26-2008
    Location
    North Myrtle Beach
    MS-Off Ver
    365 Business
    Posts
    82

    Copy data from multiple sheets

    I am using the following code to copy data from multiple tabs to a summary tab - it is only supposed to copy the data in the rows if the cells in Column A have data in them, its working, but for some reason it is copying the data in columns Y and Z for four extra rows even though there is no data in column A for those rows.....driving me crazy! I am attaching a sample of the workbook here as well - hoping someone can figure out what I have coded wrong I am working in Office 2007.

    Sub SumData()
    '
    ' SummarizeData from Timesheets
    '
        Sheets("Jorge Montoya").Select
        Range("A9").Select
        Set r = Range("A9:A27")
        For n = 1 To r.Rows.Count
        myval = ActiveCell.Value
        
        If InStr(myval, "") > 0 Then
            ActiveCell.Range("A1:Z1").Select
            Selection.Copy
        Sheets("Total by Job_Code").Select
        NextRow = Range("A65536").End(xlUp).Row + 1
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=True, Transpose:=False
        ActiveCell.Offset(1, 0).Select
        End If
        Sheets("Jorge Montoya").Select
        
        ActiveCell.Offset(1, 0).Select
        Next n
        
        Range("A9").Select
        
          
        Sheets("Felipe Estrada").Select
        Range("A9").Select
        Set r = Range("A9:A27")
        For n = 1 To r.Rows.Count
        myval = ActiveCell.Value
        
        If InStr(myval, "") > 0 Then
            ActiveCell.Range("A1:Z1").Select
            Selection.Copy
        Sheets("Total by Job_Code").Select
        NextRow = Range("A65536").End(xlUp).Row + 1
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=True, Transpose:=False
        ActiveCell.Offset(1, 0).Select
        End If
        Sheets("Felipe Estrada").Select
        
        ActiveCell.Offset(1, 0).Select
        Next n
        
        Range("A9").Select
        
        
        Sheets("Kimberly Garcia").Select
        Range("A9").Select
        Set r = Range("A9:A27")
        For n = 1 To r.Rows.Count
        myval = ActiveCell.Value
        
        If InStr(myval, "") > 0 Then
            ActiveCell.Range("A1:Z1").Select
            Selection.Copy
        Sheets("Total by Job_Code").Select
        NextRow = Range("A65536").End(xlUp).Row + 1
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=True, Transpose:=False
        ActiveCell.Offset(1, 0).Select
        End If
        Sheets("Kimberly Garcia").Select
        
        ActiveCell.Offset(1, 0).Select
        Next n
        
        Range("A9").Select
        
    End Sub
    There will end up being about 30 different tabs that it will need to copy from, but the attachment I am including only has 3.

    Thank you in advance for any help!
    Last edited by bjohnsonac; 08-27-2009 at 07:33 AM.

  2. #2
    Forum Contributor
    Join Date
    02-27-2008
    Posts
    764

    re: Copy data from multiple sheets

    Hi
    NO attachments!
    try these codes
    Sub SumData()
    Dim a As Long, b As Long, d As Long, x As Long
    d = 2
        For a = 1 To Sheets.Count
            If Worksheets(a).Name <> "Total by Job_Code" Then
            x = Worksheets(a).Cells(Rows.Count, 1).End(xlUp).Row
            Worksheets("Total by Job_Code").Cells(d, 1) = Worksheets(a).Name
                For b = 9 To x
                    If Worksheets(a).Cells(a, 1) <> "" Then
                    Worksheets(a).Range("A" & b & ":Z" & b).Copy
                    Worksheets("Total by Job_Code").Cells(d, 2).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
                            :=True, Transpose:=False
                    d = d + 1
                    End If
                Next b
            d = d + 1
            End If
        Next a
    End Sub
    Ravi

  3. #3
    Registered User
    Join Date
    09-26-2008
    Location
    North Myrtle Beach
    MS-Off Ver
    365 Business
    Posts
    82

    Re: Macro for copying data from multiple sheets

    I tried that code and it only copied the name of the person over - I am trying to attach my sample workbook again
    Attached Files Attached Files

  4. #4
    Forum Contributor
    Join Date
    02-27-2008
    Posts
    764

    Re: Copy data from multiple sheets

    Hi
    try the sumdata from module2 in the attached file
    Ravi
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    09-26-2008
    Location
    North Myrtle Beach
    MS-Off Ver
    365 Business
    Posts
    82

    Re: Copy data from multiple sheets

    That works great thank you - one issue though...I don't want the names of the people transferred over, but can't figure out from your code what part is telling it to do that....

  6. #6
    Registered User
    Join Date
    09-26-2008
    Location
    North Myrtle Beach
    MS-Off Ver
    365 Business
    Posts
    82

    Re: Copy data from multiple sheets

    I figured it out Thank you again for all your help! One of these days I will figure out all the fancy code and be able to reduce my multi-page macros down to a short one like you supplied me!

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