+ Reply to Thread
Results 1 to 8 of 8

extract information from various worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    05-22-2012
    Location
    Calgary, canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    extract information from various worksheet

    Hi,

    Right now, I have the vba code in place to extract the pivot tables from employees tab and display them in the master tab.
    I am trying to extract the names employees (cell C3) from various tabs to the master tab and display them a cell above the pivot table on the master tab.

    is this the right code to extract names?

    ' EmpName = ws.cells(c,3).Copy Destination:=worksheets("Master").cells(CellRef-1,1)
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    05-22-2012
    Location
    Calgary, canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: extract information from various worksheet

    Any suggestions?

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: extract information from various worksheet

    Change it to
    ws.range("C3").Copy worksheets("Master").cells(CellRef-1,1)
    Last edited by arlu1201; 05-25-2012 at 03:08 PM.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Registered User
    Join Date
    05-22-2012
    Location
    Calgary, canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: extract information from various worksheet

    Hi Arlu,

    I am getting a santax error on the code that you provided..

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: extract information from various worksheet

    Can you please provide the rest of the code?

  6. #6
    Registered User
    Join Date
    05-22-2012
    Location
    Calgary, canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: extract information from various worksheet

    Hi,

    Please see attached. Below are the codes. they can also be found in the macro edit function.

    Sub Master()
    
        Dim ws As Worksheet
        Dim CellRef As Long
        Dim EmpName As String
    
    
    CellRef = 4
    
       
        For Each ws In ThisWorkbook.worksheets
        
               If ws.Name <> "Master" Then
          
                
                    ws.PivotTables("PivotTable1").TableRange2.Copy Destination:=worksheets("Master").Cells(CellRef, 1)
        
               
                    
                    EmpName = ws.range("C3").Copy worksheets("Master").cells(CellRef-1,1)
                    
                    CellRef = CellRef + ws.PivotTables("PivotTable1").TableRange2.Rows.Count + 5
                    
                    
            
            End If
        
        Next ws
    
    
    End Sub
    Attached Files Attached Files

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: extract information from various worksheet

    This is your updated code
    Sub Master()
    
    Dim ws As Worksheet
    Dim CellRef As Long
        
    CellRef = 4
    
        'runs a loop for the same number of times as the number of worksheets in the active workbook
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> "Master" Then
            'copies the pivot table from various tabs to the master tab in cell (CellRef, 1)
             ws.PivotTables("PivotTable1").TableRange2.Copy Destination:=Worksheets("Master").Cells(CellRef, 1)
             Worksheets("Master").Cells(CellRef - 1, 1).Value = ws.Cells(3, 3).Value
             CellRef = CellRef + ws.PivotTables("PivotTable1").TableRange2.Rows.Count + 5
        End If
    Next ws
    
    End Sub

  8. #8
    Registered User
    Join Date
    05-22-2012
    Location
    Calgary, canada
    MS-Off Ver
    Excel 2010
    Posts
    25

    Re: extract information from various worksheet

    Works Cheers!!

+ 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