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.

Hf0byNHKKKm y,XAhtz0m,7i7UD,Gr1qlz wC0KEsVocv DcSWjG3Xo2x3L3Pz,nzzjh9Jb44UjO CV5KGcmQUuz,U9B wQ5bU71
hwgllp5wDomcsi

Popular posts from this blog

Rothschild family

Boo (programming language)