I would like to ask you for help with my macro that I want to write. I tried to look for solution on this website but I couldn't find anything.
I have 9 diferent worksheets in Workbook_(current month)- for instance Workbook_July.xls where I have to copy data with 9 different criteria from the report ("report_(current month).xls") ,the name is different every month.
Worksheet names: "1", "2", "3", "4", "5", "6", "7", "8", "9". (Workbook_(current month))
Autofilter criteria in cell A8: "EN > 1", "EN > 2", "EN > 3", "EN > 4", "EN > 5", EN > 6", EN > 7", "EN > 8", "EN > 9" (report_(current month).xls)
What I need to do is to filter the whole table in the report (columns A:N) and select criteria from A8. Then I need to select data from A9:J9 and N9 till the last row. The first row in the table is always the same however the number of end row is always different. I know what I can use .End(xlDown)
function but I don't know how to do this simutaneously for A9:J9 and N9.
After I select the range I need to copy and then paste the data from criteria "EN > 1" to worksheet "1", from "EN > 2" to worksheet "2" till the last criteria "EN > 9". The name of worksheets in Workbook_(current month) are always the same.
I wrote a macro that works pretty well on 1 worksheet but I want to do this for all 9 worksheets (please note that there are more worksheets in the workbook):
Sub copyandpaste1()
Application.ScreenUpdating = False
ActiveWorkbook.Sheets("1").Activate
yourPath = "C:\Users\" & Environ("username") & "\Desktop\test\VTR tracker\"
file = Dir(yourPath & "Report*.xls")
Do While file <> vbNullString
Workbooks.Open (yourPath & file)
file = Dir()
Loop
Rows("8:8").Select
Selection.AutoFilter
ActiveSheet.Range("$A$8:$N$50000").AutoFilter Field:=1, Criteria1:= _
"EN > 1"
With Worksheets("Report*").AutoFilter.Range
Range("B" & .Offset(2, 9).SpecialCells(xlCellTypeVisible)(9).Row).Select
End With
Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(0, 8)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
For Each wb In Application.Workbooks
If wb.Name Like "Workbook*" Then
wb.Activate
End If
Next wb
Worksheets("1").Activate
lMaxRows = Cells(Rows.Count, "B").End(xlUp).Row
Range("B" & lMaxRows + 1).Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Range(ActiveCell.Offset(0, 0), ActiveCell.Offset(0, 8)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
For Each wb In Application.Workbooks
If wb.Name Like "Workbook*" Then
wb.Activate
End If
Next wb
Worksheets("1").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Range("A4").Select
Application.CutCopyMode = False
Application.ScreenUpdating = False
For Each w In Workbooks
If w.Name Like "*Report*" Then
Windows(w.Name).Activate
Exit For
End If
Next w
With Worksheets("Report").AutoFilter.Range
Range("B" & .Offset(14, 9).SpecialCells(xlCellTypeVisible)(9).Row).Select
End With
Range(ActiveCell.Offset(0, 12), ActiveCell.Offset(0, 12)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
For Each wb In Application.Workbooks
If wb.Name Like "Viator_Translation_Tracker_*" Then
wb.Activate
End If
Next wb
Worksheets("1").Activate
lMaxRows = Cells(Rows.Count, "N").End(xlUp).Row
Range("N" & lMaxRows + 1).Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
End Sub
One of the most important thing is that I update Workbook_(current month) every day and the data needs to be copied after the last row with content, even if it is a duplicate. So if the last row on Monday is 71 then on Tuesday I need to start copying data from report to Workbook from 72. Please note that I want to start copying data in row A3 (Rows 1 and 2 contains headers and formulas)
Thanks in advance.