我有點新手VBA用戶,並且我創建了一個具有多個選項卡的用戶窗體的工作簿。當用戶選擇適當的選項卡並輸入數據時,它將被轉移到適用的工作表中。我在工作表上有一個命令按鈕,點擊它時會提示日期範圍,然後我希望它從每個適用的工作表中提取傳輸的數據,並將其放在每個用戶的單獨的新工作表上(因爲每個人的數據都不相同)。我編譯的下面的VBA代碼沒有正確處理。相反,它只從一個工作表中提取數據,並將其放在所有新的單個工作表上。VBA代碼從多個表格提取到新的多個表格
Sub Copy_Click()
Dim startdate As Date, enddate As Date
Dim rng As Range, destRow As Long
Dim shtSrc1 As Worksheet
Dim shtSrc2 As Worksheet
Dim shtSrc3 As Worksheet
Dim shtDest1 As Worksheet
Dim shtDest2 As Worksheet
Dim shtDest3 As Worksheet
Dim c As Range
Set shtSrc1 = Sheets("Recruiter")
Set shtSrc2 = Sheets("SrRecruiter")
Set shtSrc3 = Sheets("RecruiterSpc")
Set shtDest1 = Sheets("Extract_Recrt")
Set shtDest2 = Sheets("Extract_SrRecrt")
Set shtDest3 = Sheets("Extract_RecrtSpc")
destRow = 2 'start copying to this row
startdate = CDate(InputBox("Input desired start date for report data"))
enddate = CDate(InputBox("Input desired end date for report data"))
'don't scan the entire column...
Set rng = Application.Intersect(shtSrc1.Range("A:A"), shtSrc1.UsedRange)
Set rng = Application.Intersect(shtSrc2.Range("A:A"), shtSrc2.UsedRange)
Set rng = Application.Intersect(shtSrc3.Range("A:A"), shtSrc3.UsedRange)
For Each c In rng.Cells
If c.Value >= startdate And c.Value <= enddate Then
c.Offset(0, 0).Resize(1, 25).Copy _
shtDest1.Cells(destRow, 1)
c.Offset(0, 0).Resize(1, 25).Copy _
shtDest2.Cells(destRow, 1)
c.Offset(0, 0).Resize(1, 25).Copy _
shtDest3.Cells(destRow, 1)
destRow = destRow + 1
End If
Next
End Sub
任何人都可以請告訴我我做錯了什麼,以及如何解決它。
是的!!!!謝謝soooo,這正是我所需要/想要的,它完美地工作,它甚至用新的數據。非常感謝這個論壇的所有用戶在忙碌的日程安排中幫助其他人,非常感謝!:) –
很高興幫助。如果我填好了您的問題,請將我的答案標記爲解決方案。謝謝 – user3598756
我不確定如何將答案標記爲解決方案....我是否需要爲該帖子做一些特別的事情? –