Forum Discussion

Bixente's avatar
Bixente
Copper Contributor
Aug 11, 2021
Solved

Excel Makros code seems right but doesn't work as expected

Hello I'd love to get  some Data from a few sheets, listed on a single sheet. I wrote this code: Sub Tabelle_zusammanfassen() Dim i As Integer Dim Zusammenfassung As Worksheet Set Zusamm...
  • Subodh_Tiwari_sktneer's avatar
    Aug 14, 2021

    Bixente 

    Please try this...

    Sub CopyDataToMasterSheet()
    Dim wsSummary       As Worksheet
    Dim ws              As Worksheet
    Dim dlr             As Long
    Dim RngTotal        As Range
    Dim r               As Long
    
    Application.ScreenUpdating = False
    
    Set wsSummary = Worksheets("Summary")
    
    For Each ws In ThisWorkbook.Worksheets
        If Not ws Is wsSummary Then
            Set RngTotal = ws.Columns(1).Find(what:="Total", lookat:=xlPart)
            If Not RngTotal Is Nothing Then
                r = RngTotal.End(xlUp).Row
                If wsSummary.Range("H1").Value = "" Then
                    dlr = 1
                Else
                    dlr = wsSummary.Cells(Rows.Count, "H").End(xlUp).Row + 1
                End If
                ws.Range("A" & r).Copy wsSummary.Range("H" & dlr)
                ws.Range("J" & r).Copy wsSummary.Range("I" & dlr)
                ws.Range("Q" & RngTotal.Row).Copy wsSummary.Range("J" & dlr)
            End If
        End If
    Next ws
    Application.ScreenUpdating = True
    End Sub

     

    In the attached, you may click the button called "Copy Data" on Summary Sheet to run the code.

     

     

Resources