Hi Guys, I have a code below that works by finding the last row of the source file and paste it into the destination sheet of another workbook, all the data is stored from Column C to L. the transfer works fine but only Transfers C to J the misses out the last two cells. Can someone help me out on this
Sub LastRowToExport1()
Dim lastS1Row As Long 'Last Source Row
Dim nextS2Row As Long 'Next Target Row
Dim lastCol As Long 'Last Column on Source Sheet
Dim s1Sheet As Worksheet, s2Sheet As Worksheet
Dim source As String 'Source worksheet name
Dim target As String 'Target worksheet name
Dim path As String
'---SET SHEET NAMES HERE---
source = "Sheet2" 'Source Worksheet Name
path = "T:\ROC-IT PROGAM\OFI Management\OFI Register.xlsm" 'Target File Path including file name and extension
target = "ALL OFIs" 'Target Worksheet Name
'WARNING - THIS LINE WILL DISABLE NORMAL BREAKING - IN CASE OF LOOP
Application.EnableCancelKey = xlDisabled 'Disables breaking when opening new book
'Define worksheets
Set s1Sheet = ThisWorkbook.Sheets(source) 'Source Sheet
Set s2Sheet = Workbooks.Open(path).Sheets(target) 'Target Sheet
'Get the last row on each sheet and set the NEXT Row on the target. Also total columns.
lastS1Row = s1Sheet.Range("C" & Rows.Count).End(xlUp).Row
nextS2Row = s2Sheet.Range("C" & Rows.Count).End(xlUp).Row + 1
lastCol = s1Sheet.Cells(3, Columns.Count).End(xlToLeft).Column 'Headers in Row 1
'---COPY ENTIRE ROW--- Loop through Cells by column
For lCol = 1 To lastCol
s2Sheet.Cells(nextS2Row, lCol) = s1Sheet.Cells(lastS1Row, lCol)
Next lCol
'WRAP UP, SAVE EXPORTED SHEET, REACTIVATE SOURCE SHEET
s2Sheet.Activate
ActiveWorkbook.Close SaveChanges:=True
s1Sheet.Activate
End Sub
Sub LastRowToExport1()
Dim lastS1Row As Long 'Last Source Row
Dim nextS2Row As Long 'Next Target Row
Dim lastCol As Long 'Last Column on Source Sheet
Dim s1Sheet As Worksheet, s2Sheet As Worksheet
Dim source As String 'Source worksheet name
Dim target As String 'Target worksheet name
Dim path As String
'---SET SHEET NAMES HERE---
source = "Sheet2" 'Source Worksheet Name
path = "T:\ROC-IT PROGAM\OFI Management\OFI Register.xlsm" 'Target File Path including file name and extension
target = "ALL OFIs" 'Target Worksheet Name
'WARNING - THIS LINE WILL DISABLE NORMAL BREAKING - IN CASE OF LOOP
Application.EnableCancelKey = xlDisabled 'Disables breaking when opening new book
'Define worksheets
Set s1Sheet = ThisWorkbook.Sheets(source) 'Source Sheet
Set s2Sheet = Workbooks.Open(path).Sheets(target) 'Target Sheet
'Get the last row on each sheet and set the NEXT Row on the target. Also total columns.
lastS1Row = s1Sheet.Range("C" & Rows.Count).End(xlUp).Row
nextS2Row = s2Sheet.Range("C" & Rows.Count).End(xlUp).Row + 1
lastCol = s1Sheet.Cells(3, Columns.Count).End(xlToLeft).Column 'Headers in Row 1
'---COPY ENTIRE ROW--- Loop through Cells by column
For lCol = 1 To lastCol
s2Sheet.Cells(nextS2Row, lCol) = s1Sheet.Cells(lastS1Row, lCol)
Next lCol
'WRAP UP, SAVE EXPORTED SHEET, REACTIVATE SOURCE SHEET
s2Sheet.Activate
ActiveWorkbook.Close SaveChanges:=True
s1Sheet.Activate
End Sub