VBA: Copy row from SourceSheet and paste into DestSheet using dynamic rows

Multi tool use
Multi tool use


VBA: Copy row from SourceSheet and paste into DestSheet using dynamic rows



I'd like to copy area from another workbook.



SOURCE: The area starts from J15 to last row of J column. I'm having trouble with the syntax.



DESTINATION: The area where the paste is the same area as in the Sourceworkbook, but K Column (K15 to last row of J column)



The problem is the with statement. I keep getting this error:
https://pasteboard.co/HsxMzPZ.jpg



Picture of the sourcesheet for clarification
https://pasteboard.co/Hs8gDsF.jpg


Public Sub Subledger_Makro()


Dim Subwb As Workbook
Dim Subsht As Worksheet
Dim Sourcewb As Workbook
Dim SourceSht As Worksheet



Set Subwb = ActiveWorkbook
Set Subsht = Subwb.Sheets("SAPBW_DOWNLOAD")

SourceFile = Application.GetOpenFilename(, , "Open yesterdays Subledger Report")

Set Sourcewb = Workbooks.Open(SourceFile)
Set SourceSht = Sourcewb.Sheets("SAPBW_DOWNLOAD")



'Copies the previous day Subledger (SourceSht) report J-Column to new the Subledgers (DestSht) K-column
' DestSheet is todays Subledger
' SourceSheet is the previous day Subledger


With SourceSht
.Range(.Cells(15, "J"), .Cells(.Cells(.Rows.Count, "J").End(xlUp).Row, "J")).Copy Destination:=Subwb.Subsht.Range("K15")
End With

Application.CutCopyMode = False





End Sub




1 Answer
1



Replace this line


.Range(.Cells(15, "J"), .Cells(.Cells(.Rows.Count, "J").End(xlUp).Row, "J")).Copy Destination:=Subwb.Subsht.Range("K15")



With


.Range(.Cells(15, "J"), .Cells(.Cells(.Rows.Count, "J").End(xlUp).Row, "J")).Copy
Subsht.Range("K15").PasteSpecial xlPasteAll






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

0WgHVbSd aZUXlPJTb7H v5 1lYZ,NqBoXELGjYrqSub,XCMO,BkZLWDg8NT 7gAvX8J,OBga0f Ycox,Gq
rz0tOwb7 QmEw,Lap zmR PCfsrTe1AYTvoG,sFkFN,0B4S8cBoSZJomww0OGzz63nz5RTJvqPFg,x33ojQ38pzZuWr9o4

Popular posts from this blog

Rothschild family

Cinema of Italy