这是我第一次来到这里和VBA的第一步(我已经做了一些成功的编码)。
这是我的问题:我有一个工作簿,每天在2个工作表中手动更新数据。在另一个工作簿上,我希望获得相同的数据(它运行一些不同的报告),所以如果比较两个工作簿上的日期,我试图从第一个中提取新数据。现在我正在使用公式,但最终得到一个非常大的文件(> 100Mb)。
经过长时间的网络搜索,尝试使用一些示例和解释,这就是我所拥有的,但我无法设法运行它。你们有人可以帮我吗?我知道我会把自己与细胞和行混淆,这就是为什么我需要一些帮助:)
Sub Copy_Paste_Date_based()
Dim startdateN As Date, enddateN As Date, startdateS As Date, enddateS As Date
Dim rng As Range, rngN As Range, rngS As Range
Dim destRowN As Long, destRowS As Long
Dim wbDest As Workbook
Dim shtSrcN As Worksheet, shtSrcS As Worksheet, shtDestN As Worksheet, shtDestS As Worksheet
Dim c As Range
Set wbDest = Workbooks.Open(Filename:="G:\Construction ENGINEERING\01. Follow Up\05. Monitoring\03. Tunnels\03. Ground water\Piezometric level\OLD\Piezometer_CP_GW_Report_vTEST.xlsm")
Set shtSrcN = ThisWorkbook.Sheets("ALLData - NORTH")
Set shtSrcS = ThisWorkbook.Sheets("ALLData - SOUTH")
Set shtDestN = Workbooks("Piezometer_CP_GW_Report_vTEST.xlsm").Worksheets("Piezometer_data NORTH")
Set shtDestS = Workbooks("Piezometer_CP_GW_Report_vTEST.xlsm").Worksheets("Piezometer_data SOUTH")
Set rngN = shtSrcN.Range("A:A")
Set rngS = shtSrcS.Range("A:A")
startdateN = shtDestN.Range("A1").End(xlUp).Value
enddateN = shtSrcN.Range("AQ2").Value
startdateS = shtDestS.Range("A1").End(xlUp).Value
' currently stuck debugging the line below, can't understand what is wrong
enddateS = shtSrcS.Range("AG2").Value
Set rng = Application.Intersect(shtSrcN.Range("A:A"), shtSrcN.UsedRange)
'Find range based on dates for Data in North and past it
For Each c In rng.Cells
If c.Value >= startdateN And c.Value <= enddateN Then
'Starting one cell to the right of c,
' copy a 70-cell wide block to the other sheet,
' pasting right of the las date value column
c.Offset(0, 0).Resize(0, 70).Copy _
shtDestN.startdateN.Offset(0, 1).Select
End If
Next
'Find range based on dates for Data in South and past it
For Each c In rng.Cells
If c.Value >= startdateS And c.Value <= enddateS Then
'Starting one cell to the right of c,
' copy a 104-cell wide block to the other sheet,
' pasting right of the las date value column
c.Offset(0, 0).Resize(0, 104).Copy _
shtDestS.startdateS.Offset(0, 1).Select
End If
Next
End Sub