我想从另一个工作簿复制一组数据,我的代码将其复制到最后一组数据下。我正在从工作表“Übersciht”复制到工作表“Daten”。我希望在粘贴数据集后立即将日期粘贴到“日期”中的每个粘贴行中
Sub Schaltfläche1_Klicken()
Application.DisplayAlerts = False
Dim LastRow As Long
Dim i As Long
Dim mWB As Workbook 'This Workbook
Dim dWB As Workbook 'Data Workbook
'set the Main Workbook
Set mWB = ThisWorkbook
Dim filePath As String
filePath = Application.GetOpenFilename
Debug.Print filePath
'Set the Data Workbook
Set dWB = Workbooks.Open(filePath)
Dim dataSh As Worksheet
Set dataSh = dWB.Sheets("Fuhrparksteuerung XLS Export")
'copy the Data Table
dataSh.Range("A1").CurrentRegion.Copy
'Paste the Data Table
mWB.Sheets("Übersicht").Range("A1").PasteSpecial xlPasteAll
dWB.Close False
Application.DisplayAlerts = True
With ThisWorkbook.ActiveSheet
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
LastRow = Sheets("Daten").Range("B65536").End(xlUp).Offset(1, 0).Row
Range("A4:M25").Copy Destination:=Sheets("Daten").Range("B" & LastRow)
Sheets("Daten").Range("A" & LastRow) = Range("A2").Value
End Sub
我尝试复制/粘贴此代码,但我需要将单元格 A2 中的日期粘贴到“日期”表中的每个粘贴行中。
请帮助我,非常感谢:)
将这三行代码更改为:
LastRow = Sheets("Daten").Range("B65536").End(xlUp).Offset(1, 0).Row
Sheets("Daten").Range("A2:A" & LastRow - 1).Value = mWB.Sheets("Übersicht").Range("A2").Value
注意:如果您要直接给单元格赋值,则无需复制并使用粘贴板