+ Reply to Thread
Results 1 to 5 of 5

Consolidate data from two sheets of same workbook

Hybrid View

  1. #1
    Registered User
    Join Date
    06-18-2013
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    16

    Consolidate data from two sheets of same workbook

    Hi Team,

    I have a worksheet which is having two data sheets getting data from SQL Query. Now Issue is that I need to combine both data into one sheet. I have tried to create macro which copy data from both worksheets one by one and copy it to one. But it does not work properly. I need to just combine both tables. I have attached an example sheet for the same.

    Is there any function that can help to combine this data or macro. I have tried to modify SQL query but its not working. So I think only excel function or macro can do this.
    Attached Files Attached Files
    Last edited by indianhp; 06-19-2013 at 01:19 AM. Reason: Its Solved

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Consolidate data from two sheets of same workbook

    Hi and welcome to the forum

    What would your expected outcome look like?
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Consolidate data from two sheets of same workbook

    @indianhp

    with the great help of other forummembers (Nilem and AB33) in the link below. I was able to made this code for your sheet.

    http://www.excelforum.com/excel-prog...50#post3285950

    Sub integratie_Oeldere()
    
    Dim wsTest As Worksheet
    
    'check if sheet "ouput" already exist
    
    Const strSheetName As String = "Consolidated"
     
    Set wsTest = Nothing
    On Error Resume Next
    Set wsTest = ActiveWorkbook.Worksheets(strSheetName)
    On Error GoTo 0
     
    If wsTest Is Nothing Then
        Worksheets.Add.Name = strSheetName
    End If
    
    With Sheets("Consolidated")
        .UsedRange.ClearContents
        .Range("A1:E1").Value = Array("sheet", "Task", "Type", "Key Patient", "Key Doctor")
        For Each sh In Sheets
            With sh
                If .Name <> "Consolidated" Then
                    Rng = .Cells(Rows.Count, 1).End(xlUp).Row - 1
                    If Rng > 0 Then
                        Sheets("Consolidated").Cells(Rows.Count, 1).End(xlUp)(2).Resize(Rng) = .Name
                        Sheets("Consolidated").Cells(Rows.Count, 2).End(xlUp)(2).Resize(Rng, 4) = .Range("A2").Resize(Rng, 4).Value
                    End If
                End If
            End With
        Next
        .Columns("A:Z").EntireColumn.AutoFit
    End With
    End Sub
    Attached Files Attached Files
    Last edited by oeldere; 06-18-2013 at 02:54 PM.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  4. #4
    Registered User
    Join Date
    06-18-2013
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    16

    Re: Consolidate data from two sheets of same workbook

    Hi oeldere,

    Its working great as expected thanks for such a quick response. Actually I found its amazing that i also have a column in sheet which shows that from which i get the data. So, for any audit i can directly search that in perticular sheet from which that data belongs...

    Thank you very much..

  5. #5
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Consolidate data from two sheets of same workbook

    Thanks for the reply.

    Glad I could help.

+ 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