MarcMoolenaar
New Member
- Joined
- Jul 1, 2024
- Messages
- 3
- Office Version
- 2019
- Platform
- Windows
I want to copy five ranges of cells from the active worksheet to sheet of another workbook. Somehow the selected data is not copied and the target ranges remain empty. This is what I did so far:
it seems simple enough ...
VBA Code:
Sub KopieerSchutbladInfo()
Dim sourceWorkbook As Workbook
Dim sourceWorksheet As Worksheet
Dim sourceRange As Range
Dim targetWorkbook As Workbook
Dim targetWorksheet As Worksheet
Dim targetRange As Range
Dim sourceWorkbookPath As String
Dim targetWorkbookPath As String
Dim Targetline As Integer
' Define the path to the source workbook (that's the actual, already opened workbook)
Set sourceWorkbook = ThisWorkbook
Set sourceWorksheet = sourceWorkbook.ActiveSheet
' Define the path to the target workbook (this one is closed at this moment in time)
targetWorkbookPath = "F:\Sales\Schutblad data.xlsx"
Set targetWorkbook = Workbooks.Open(targetWorkbookPath)
Set targetWorksheet = targetWorkbook.Sheets("Gegevens")
Targetline = targetWorksheet.Range("A2").Value
'Kopieer de gegevens van het schutblad naar het databestand
' Copy order data
Set sourceRange = sourceWorksheet.Range("B4")
Set targetRange = targetWorksheet.Range("A" & Targetline)
sourceRange.Copy
targetRange.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
' Save and close the target workbook
targetWorkbook.Save
targetWorkbook.Close
End Sub
it seems simple enough ...
Last edited by a moderator: