I have a need to merge a list of reports in the following format
- Column 1 is a number
- Column 2 is a string
- Max rows is dynamic
In such a fashion as to sum the numbers in column 1 for strings that match (removing duplicates)
Currently I am merging the csv files with this
Dim files() As String
files = AllFiles(GetFolder) 'returns array of files in folder
Dim i As Long
For i = 0 To UBound(files)
Windows("Monthly KB Page Access Report Generator.xls").Activate
ActiveCell.Value = files(i)
wrkbookvar2 = Dir(files(i))
ActiveCell.Offset(1, 0).Activate
Workbooks.Open Filename:=GetFolder & "\" & files(i)
Set dataset_workbook = ActiveWorkbook
Range(ActiveCell.SpecialCells(xlLastCell), Cells(1)).Copy
Windows("Monthly KB Page Access Report Generator.xls").Activate
Cells(ActiveCell.SpecialCells(xlLastCell).Row, 1).Select
ActiveSheet.Paste
dataset_workbook.Close
Next
This merges with 2 issues
- First cell of each report is overwritten with the reports filename
- After opening each file it prompts the user saying the clipboard has large data in it, I want to avoid this
I think the following code might work to merge my data and sum values but I cannot be sure because I am currently type missmatching due to the reports filename showing up
' Sort
Windows("filename.xls").Activate
Columns("A:B").Sort Key1:=Range("B1"), Order1:=xlAscending
' merge
LastRow = ActiveSheet.UsedRange.Rows.Count
Set r = ActiveSheet.UsedRange.Resize(1)
With Application.WorksheetFunction
For iRow = 2 To LastRow
If Cells(iRow, 2) = Cells(iRow + 1, 2) Then
Cells(iRow, 1) = Cells(iRow, 1) + Cells(iRow + 1, 1)
Rows(iRow + 1).Delete
End If
Next iRow
End With
Anybody mind helping me iron this out, I am terrible at VBA.
UPDATE: Number 1 was resolved by removing
Windows("Monthly KB Page Access Report Generator.xls").Activate
ActiveCell.Value = files(i)
wrkbookvar2 = Dir(files(i))
ActiveCell.Offset(1, 0).Activate
They were part of an older copy that I completely didnt notice.
Everything is working except I need to adjust my 'Merge to account for more then 2 instances of a value, right now it will only merge 2.