每次我运行它并尝试粘贴它时,它会继续为它读取的每一行增加lineCount。
我想获取每个varFile的唯一lineCount并将其存储在数组中。
我该怎么做?
'Collect all data from audit templates
RecursiveDir colFiles, path, "*.xlsm", True
For Each varFile In colFiles
reportRow = 2
Set reportBook = Workbooks.Open(varFile)
Set cooSummary = reportBook.Sheets("Audit")
reportRow = 2
Do While cooSummary.Cells(reportRow, 1) <> ""
lineCount = lineCount + 1
lineNum = lineNum + 1
With cooSummary
scanDate = FileDateTime(varFile)
scanned = lineCount
auditor = .Cells(1, 2)
End With
ReDim Preserve reportArray(3, lineNum)
reportArray(0, lineNum) = scanDate
reportArray(1, lineNum) = scanned
reportArray(2, lineNum) = auditor
reportRow = reportRow + 1
Loop
reportBook.Close SaveChanges:=False
Next varFile
'Paste data into Scan Sheet
For lineNum = 1 To UBound(reportArray, 2)
With scanSheet
.Cells(baseRow, 1) = reportArray(0, lineNum) 'Date Scanned
.Cells(baseRow, 2) = reportArray(1, lineNum) 'Scanned
.Cells(baseRow, 3) = reportArray(2, lineNum) 'Auditor
.Cells(baseRow, 4).Formula = "=IF(LEN(C" & baseRow & ")>10,C" & baseRow & ",IF(LEN(C" & baseRow & ")>=5,TRIM(LEFT(TRIM(C" & baseRow & "),3)), C" & baseRow & "))" 'Auditor1
.Cells(baseRow, 5).Formula = "=IF(LEN(C" & baseRow & ")>10,"""",IF(LEN(C" & baseRow & ")>=5,TRIM(RIGHT(TRIM(C" & baseRow & "),3)), """"))" 'Auditor 2
.Cells(baseRow, 6).Formula = "=IF(E" & baseRow & "="""",B" & baseRow & ",B" & baseRow & "/2)" 'Average Scanned
.Cells(baseRow, 7).Formula = "=IF(AND(ISNA(VLOOKUP(D" & baseRow & ",Summary!A:C,1,0)),ISNA(VLOOKUP(E" & baseRow & ",Summary!A:C,1,0))),""MISSING"",""GOOD"")" 'Auditor CK
End With
baseRow = baseRow + 1
Next lineNum