我正在尝试将一组单元格从一个工作表复制到另一个工作表。但是我需要通过仔细检查月份来确保它进入正确的空间。我最初的想法是找到最后一个值,检查它发生的日期,然后如果它是所需的日期,则声明一个新变量并将该变量地址传递给复制和粘贴代码。但代码在复制和粘贴区域失败,我认为这是我如何定义变量的结果,但我需要一个比我更聪明的想法来弄清楚我哪里出错了。想法?
Sub perfupdate()
Application.ScreenUpdating = False
Dim sh1, sh2 As Worksheet
Set sh1= ThisWorkbook.Sheets("sheet1")
Set sh2= ThisWorkbook.Sheets("sheet2")
Dim datecell As Date
datecell = sh2.Range("a2").End(xlToRight).Offset(-1, 1).Value
Dim dc As Range
Set dc= sh2.Range("A2").End(xlToRight).Offset(-1, 1)
dcadd = dc.Address
If Month(datecell) = Month(today) And Year(datecell) = Year(today) Then
actcell = sh2.Range(dcadd).Offset(0, -1)
Else
actcell = sh2.Range(dcadd)
End If
sh1.Range("BB3", "BB7").Copy Destination:=sh2.Range(actcell.Address).Offset(1, 0)
End Sub