我有一个从一月到十二月的每个月的工作表和一个名为报告的工作表,复制的数据在哪里
在月表中,我有以下数据
ID NAME # DAYS OF VACATION
1 GEORGE 3
2 MARY 5
每个月表都有相同的名称,但名称未绑定到相同的 ID 我想要在摘要表中做的是
ID NAME # DAYS OF VACATION MONTH
1 GEORGE 3 JAN
2 GEORGE 2 FEB
SUM GEORGE 5 YEAR
我设法做的是从一个月表复制到报告,但我不能从所有月表中复制多个,我不知道如何做 SUM 部分。有任何想法吗?
Sub SearchForString()
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
On Error GoTo Err_Execute
'Start search in row 2
LSearchRow = 2
'Start copying data to row 2 in Sheet2 (row counter variable)
LCopyToRow = 2
fname = InputBox("Enter Name", "Enter Data")
If fname = "" Then
While fname = ""
MsgBox ("Enter Name")
fname = InputBox("Enter Name", "Enter Data")
Wend
End If
While Len(Range("A" & CStr(LSearchRow)).Value) > 0
'If value in column E = "Mail Box", copy entire row to Sheet2
If Sheets("JAN").Range("B" & CStr(LSearchRow)).Value = fname Then
'Select row in Sheet1 to copy
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy
'Paste row into Sheet2 in next row
Sheets("REPORT").Select
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
ActiveSheet.Paste
'AddWatermark ("JAN")
'Move counter to next row
LCopyToRow = LCopyToRow + 1
End If
'Go back to Sheet1 to continue searching
Sheets("REPORT").Select
LSearchRow = LSearchRow + 1
Wend
'Position on cell A3
Application.CutCopyMode = False
Range("A3").Select
MsgBox "COPY DONE"
Exit Sub
Err_Execute:
MsgBox "ERROR"
End Sub