I’m new in VBA and I’m trying to copy and paste filtering data into another sheet. When I launch my code, nothing happens, no error messages either.
Input Sheet "DONNEE DRAFT" Columns K and L :
BU (K) | AL (L) | |
---|---|---|
1 | FRQ40 | ALPYIP |
2 | FRXK0 | ALPAJW |
3 | FRRZ0 | ALPK29 |
4 | FR500 | ALPAGD |
5 | FR500 | ALPH51 |
6 | FR040 | ALPH51 |
7 | etc... | etc... |
Note: data in Column K -> VlookUp formula
I'm adding a filter in this table > filtering in BU (Columns K) : "FR500" I copy the column K and L then past into another sheet:
In Columns A :BU "FR500" and in C :AL linked to FR500). In the example bellow it's what we have in line 6 and 7 (It won't start at this specified row always).
Outpout Expect in Sheet "IML" :
BU (A) | BU AFF (B) | AL (C) | |
---|---|---|---|
1 | data | other data | data |
2 | data | other data | data |
3 | data | other data | data |
4 | data | other data | data |
5 | data | other data | data |
6 | FR500 | other data | ALPH51 |
7 | FR500 | other data | ALPAGD |
Here the code (I tried only to copy/paste "BU"):
Dim FR500 As Range
Dim LastRow As Double
Dim LastRow2 As Double
LastRow = Sheets("DONNEE DRAFT").Range("K" & Rows.Count).End(xlUp).Row + 1 'last row
LastRow2 = Sheets("IML").Range("A" & Rows.Count).End(xlUp).Row + 1
Set FR500 = Sheets("DONNEE DRAFT").Range("K1").CurrentRegion
Sheets("DONNEE DRAFT").AutoFilterMode = False 'turning off all filter
FR500.AutoFilter Field:=1, Criteria1:="FR500" 'filtering data
Sheets("DONNEE DRAFT").Range("K" & LastRow).Copy
Sheets("IML").Range("A" & LastRow2).PasteSpecial xlPasteValues