Macro help.. Copying data from a table until the next empty row.

mccaco

New Member
Joined
Aug 27, 2014
Messages
8
I have been trying to create a macro which will copy all the data from certain columns in a table (B to G) between row 24 and the next empty row (as the table found on a sheet called "Data" is updated frequently so the final row of data will be moved further down the sheet). then pasted onto "sheet3" in cell A1. I havn't had much luck so far so I would be grateful if someone could give me a hand.

Thank you in advanve for any help.

Regards
Mccaco
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try

Code:
Sub test()
Dim LR As Long
With Sheets("Data")
    LR = .Range("B" & Rows.Count).End(xlUp).Row
    .Range("B24:G" & LR).Copy Destination:=Sheets("Sheet3").Range("A1")
End With
End Sub
 
Upvote 0
Code:
 Sub LastModifiedFile()
    
    Dim dirName As String
    Dim fName As String
    Dim fileTime As Date
    Dim FileName As String
    Dim LatestFile As String
    Dim wbSource As Workbook
    Dim wbFile As Workbook
    Dim LR As Long
    Set wbSource = ActiveWorkbook
    
    dirName = "P:\New Issues\"
    fName = Dir(dirName & "*.*")
    
    While fName <> ""
        If FileDateTime(dirName & fName) > fileTime Then
            LatestFile = fName
            fileTime = FileDateTime(dirName & fName)
        End If
        fName = Dir()
    Wend
    
    If LatestFile = "" Then
        MsgBox "There are no files in the directory"
    Else
        Workbooks.Open dirName & LatestFile
        
        Set wbFile = ActiveWorkbook
        
        With Sheets("Data")
           LR = .Range("B" & Rows.Count).End(xlUp).Row
          .Range("B24:G" & LR).Copy Destination:=wbSource.Sheets("Sheet3").Range("A1")
   
        wbFile.Close
    End If
End Sub

This is what I have so far, basically I want to open up the most recently modified file in a folder copy the range of data that I mentioned at the top of the thread from that workbook. Paste the data onto "sheet3" in the source workbook where the macro will be triggered then close the workbook from where the data was copied.
 
Upvote 0
Code:
 Sub LastModifiedFile()
    
    Dim dirName As String
    Dim fName As String
    Dim fileTime As Date
    Dim FileName As String
    Dim LatestFile As String
    Dim wbSource As Workbook
    Dim wbFile As Workbook
    Dim LR As Long
    Set wbSource = ActiveWorkbook
    
    dirName = "P:\New Issues\"
    fName = Dir(dirName & "*.*")
    
    While fName <> ""
        If FileDateTime(dirName & fName) > fileTime Then
            LatestFile = fName
            fileTime = FileDateTime(dirName & fName)
        End If
        fName = Dir()
    Wend
    
    If LatestFile = "" Then
        MsgBox "There are no files in the directory"
    Else
        Workbooks.Open dirName & LatestFile
        
        Set wbFile = ActiveWorkbook
        
        With Sheets("Data")
           LR = .Range("B" & Rows.Count).End(xlUp).Row
          .Range("B24:G" & LR).Copy Destination:=wbSource.Sheets("Sheet3").Range("A1")
   
        wbFile.Close
    End If
End Sub

This is what I have so far, basically I want to open up the most recently modified file in a folder copy the range of data that I mentioned at the top of the thread from that workbook. Paste the data onto "sheet3" in the source workbook where the macro will be triggered then close the workbook from where the data was copied.

Basically it doesnt work and I have no idea why.
 
Upvote 0

Forum statistics

Threads
1,216,441
Messages
6,130,643
Members
449,585
Latest member
Nattarinee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top