Consulting

Results 1 to 2 of 2

Thread: Macro does not copy to the next row on the destination sheet

  1. #1

    Question Macro does not copy to the next row on the destination sheet

    The following code does successfully loop through all of thesheets in the directory however it does not paste to the next open row in thedestination sheet and instead clobbers the data in the same rows

    Can you assist?



    Sub copydatafrommulttomaster()
    Dim folderpath As String, Filepath As String, filename AsString
    folderpath = "C:\Users\Stvcass\Documents\AA_HISTORY"
    Filepath = folderpath & "*.xls*"
    filename = Dir(Filepath)
    Do While filename <> ""
    If myfile = "activity Log.xlsm" Then
    Exit Sub
    End If
    Workbooks.Open (folderpath & filename)
    Application.DisplayAlerts = False
    Range("AK4:AT15").Select
    Range("AK4:AT15").Copy
    'Application.DisplayAlerts = False
    Activewookbook.Close
    erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1,0).Row
    ActiveSheet.PasteDestination:=Worksheets("Sheet1").Range(Cells(erow, 1), Cells(erow,4))
    filename = Dir
    Loop
    Application.DisplayAlerts = True

    End Sub


  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    welcome to the forum.

    try
    Sub vbax_63379_copy_paste()
    
        Dim fPath As String, fName As String
        
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
        
        fPath = "C:\Users\Stvcass\Documents\AA_HISTORY\" '\ (trailing backslash)
        fName = Dir(fPath & "*.xls*")
        
        Do While fName <> "" And fName <> "activity Log.xlsm"
            Workbooks.Open (fPath & fName)
            ActiveSheet.Range("C1:C7").Copy
            ThisWorkbook.Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Offset(1).PasteSpecial
            ActiveWorkbook.Close False
            fName = Dir
        Loop
    
    End Sub
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •