在之前的帖子“User3598756”中提供了我的查询的代码/解决方案,如何从多张纸张中提取到多张纸张,我非常感谢您的帮助。
现在我需要按月提取数据,所以我试图修改下面的代码,希望当点击一个新的命令按钮时,它根据输入的开始/结束日期从六张纸中的每一张拉出来但是提取仅来自特定列的数据,并将结果传输到主工作表目标。但我显然没有在我试图修改的代码中做正确的事情:
Private Sub cmdRunMonthlyRpt_Click()
Dim startdate As Date, enddate As Date
Dim rng As Range, c As Range
Dim destRow(1) As Long
Dim shtSrc(1 To 6) As Worksheet
Dim shtDest(1) As Worksheet
Dim i As Long
Set shtSrc(1) = Sheets("Recruiter")
Set shtSrc(2) = Sheets("SrRecruiter")
Set shtSrc(3) = Sheets("RecruiterSpc")
Set shtSrc(4) = Sheets("SrOfcSpc")
Set shtSrc(5) = Sheets("SrOfcSpcB")
Set shtSrc(6) = Sheets("UnivRecruiter")
Set shtDest(1) = Sheets("Extract_Scorecard_Month")
destRow(1) = 2
startdate = CDate(InputBox("Input desired start date for report data"))
enddate = CDate(InputBox("Input desired end date for report data"))
For i = 1 To 6
Set rng = shtSrc(i).Range("A:A").SpecialCells(xlCellTypeConstants, xlNumbers) 'this will select only numbers constants. since dates are numbers they'll get into this range
For Each c In rng
If c.Value >= startdate And c.Value <= enddate Then
c.Offset(0, 0).Resize(1, 45).Copy Destination:=shtDest(i).Cells(destRow(i), 1)
destRow(i) = destRow(i) + 1
End If
Next c
Next i
End Sub
我认为我正在制造比需要更难的东西,所以如果有更好的方法来实现所需的输出,我会感激一些指示。我是一名试图学习VBA的行政助理。
谢谢