youbitto
New Member
- Joined
- Jun 8, 2022
- Messages
- 34
- Office Version
- 2019
- 2016
- 2013
- Platform
- Windows
Hello
I have this code to copy a specific rang to another sheet will be saved as PDF after each filtered value
after execute it shows me an error
This is the code
This is the filter Criteria1
This is the where the I copy from filtered data
And this is where I paste the filtered data and it has to be in this range
the error that show is "No cells were found"
I have this code to copy a specific rang to another sheet will be saved as PDF after each filtered value
after execute it shows me an error
This is the code
VBA Code:
Sub Enq()
Dim Ref As Range
Application.ScreenUpdating = False
lastrow = Sheets("TB").Cells(Rows.Count, "F").End(xlUp).Row
lastrowf = Sheets("Factures").Cells(Rows.Count, "F").End(xlUp).Row
Dim rngSrc As Range
Dim arrRef As Variant
Set rngSrc = Sheets("TB").Range("A5:A" & lastrow)
arrRef = rngSrc.Value2
For i = 5 To lastrow
Sheets("Enq").Range("C20:I42,L20:Q42").ClearContents
Sheets("Enq").Range("C14:Q14").ClearContents
Sheets("Enq").Range("K16:Q16").ClearContents
Sheets("Enq").Range("D17:P17").ClearContents
Sheets("Enq").Range("F18:I18").ClearContents
Sheets("TB").Cells(i, 2).Copy 'Nom
Sheets("Enq").Range("K16").PasteSpecial Paste:=xlPasteValues
Sheets("TB").Cells(i, 3).Copy 'Adresse
Sheets("Enq").Range("D17").PasteSpecial Paste:=xlPasteValues
Sheets("TB").Cells(i, 4).Copy 'Date Résil
Sheets("Enq").Range("F18").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Sheets("TB").Range("G" & i & ":U" & i).Copy 'Ref 'Ref
Sheets("Enq").Range("C14").PasteSpecial Paste:=xlPasteValues
'Filter rows based on Ref
Sheets("Factures").Range("A1:AI" & lastrowf).AutoFilter
Sheets("Factures").Range("A1:AI" & lastrowf).AutoFilter Field:=18, Criteria1:=arrRef(i - 4, 1)
'Copy filtered table and paste it in Destination cells.
Sheets("Factures").Range("E2:E24").SpecialCells(xlCellTypeVisible).Copy
Sheets("Enq").Range("C20").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Sheets("Factures").Range("O2:O24").SpecialCells(xlCellTypeVisible).Copy
Sheets("Enq").Range("G20").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Sheets("Factures").Range("E25:E46").SpecialCells(xlCellTypeVisible).Copy
Sheets("Enq").Range("L20").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Sheets("Factures").Range("O25:O46").SpecialCells(xlCellTypeVisible).Copy
Sheets("Enq").Range("O20").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
Next i
Sheets("Factures").AutoFilterMode = False
Application.ScreenUpdating = True
End Sub
This is the filter Criteria1
Fiche d'enquette.xlsm | |||
---|---|---|---|
A | |||
4 | Référence | ||
5 | 017051500050157 | ||
6 | 017051502408156 | ||
7 | 017051503018136 | ||
TB |
This is the where the I copy from filtered data
Fiche d'enquette.xlsm | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
E | O | R | ||||||||||||||
1 | Date Facturation | Montant | Référence | |||||||||||||
2 | 08/11/2022 | 369,22 | 017051500050157 | |||||||||||||
3 | 13/05/2023 | 369,22 | 017051500050157 | |||||||||||||
4 | 12/08/2023 | 369,22 | 017051500050157 | |||||||||||||
5 | 10/10/2023 | 246,15 | 017051500050157 | |||||||||||||
6 | 09/11/2020 | 2386,59 | 017051502408156 | |||||||||||||
7 | 08/05/2021 | 585,8 | 017051502408156 | |||||||||||||
8 | 07/08/2021 | 795,33 | 017051502408156 | |||||||||||||
9 | 08/11/2021 | 963,87 | 017051502408156 | |||||||||||||
10 | 07/02/2022 | 585,8 | 017051502408156 | |||||||||||||
11 | 08/05/2022 | 1269,06 | 017051502408156 | |||||||||||||
12 | 07/08/2022 | 585,8 | 017051502408156 | |||||||||||||
13 | 08/11/2022 | 415,37 | 017051502408156 | |||||||||||||
14 | 16/04/2023 | 276,91 | 017051502408156 | |||||||||||||
15 | 07/02/2022 | 2894,93 | 017051503018136 | |||||||||||||
16 | 08/05/2022 | 12017,48 | 017051503018136 | |||||||||||||
17 | 07/08/2022 | 415,37 | 017051503018136 | |||||||||||||
18 | 08/11/2022 | 415,37 | 017051503018136 | |||||||||||||
19 | 12/02/2023 | 415,37 | 017051503018136 | |||||||||||||
20 | 16/04/2023 | 276,91 | 017051503018136 | |||||||||||||
Factures |
And this is where I paste the filtered data and it has to be in this range
Fiche d'enquette.xlsm | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | |||
19 | Période | Montant (DA) | Période | Montant (DA) | |||||||||||||
20 | |||||||||||||||||
21 | |||||||||||||||||
22 | |||||||||||||||||
23 | |||||||||||||||||
24 | |||||||||||||||||
25 | |||||||||||||||||
26 | |||||||||||||||||
27 | |||||||||||||||||
28 | |||||||||||||||||
29 | |||||||||||||||||
30 | |||||||||||||||||
31 | |||||||||||||||||
32 | |||||||||||||||||
33 | |||||||||||||||||
34 | |||||||||||||||||
35 | |||||||||||||||||
36 | |||||||||||||||||
37 | |||||||||||||||||
38 | |||||||||||||||||
39 | |||||||||||||||||
40 | |||||||||||||||||
41 | |||||||||||||||||
42 | |||||||||||||||||
Enq |
the error that show is "No cells were found"