Excel VBA 将日期复制到单元格区域

问题描述 投票:0回答:1

我想从另一个工作簿复制一组数据,我的代码将其复制到最后一组数据下。我正在从工作表“Ü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

Empty Date Cells

我尝试复制/粘贴此代码,但我需要将单元格 A2 中的日期粘贴到“日期”表中的每个粘贴行中。

Tryout

请帮助我,非常感谢:)

excel vba button copy paste
1个回答
0
投票

将这三行代码更改为:

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

注意:如果您要直接给单元格赋值,则无需复制并使用粘贴板

© www.soinside.com 2019 - 2024. All rights reserved.