I have worked on this some more and I think I know where the problem may be, but can't figure out how to fix it.
There are some parameters set up for filters in a Fub routine and a Function. Here are the lines.
Sub GenerateFile(ws As Worksheet, columns As Variant, lastRow As Long, fileName As String, Optional filterColumn As String = "", Optional filterValue As String = "", Optional secondaryFilterColumn As String = "", Optional secondaryFilterValue1 As String = "", Optional secondaryFilterValue2 As String = "", Optional addSequence As Boolean = False)
Function CopyColumns(srcWs As Worksheet, destWs As Worksheet, columns As Variant, lastRow As Long, Optional filterColumn As String = "", Optional filterValue As String = "", Optional secondaryFilterColumn As String = "", Optional secondaryFilterValue1 As String = "", Optional secondaryFilterValue2 As String = "", Optional addSequence As Boolean = False) As Boolean
This is the data in the columns that belong to the filters.
| 10081200 |
|
| 2SG02011 |
28.58 |
| 2US00080 |
|
| 2FR08021 |
6.08 |
| 10081200 |
|
| 10081200 |
|
The variants that require a filter are
GenerateFile ws, columns2, lastRow, filePath1 & "UPU41\_Desc\_" & Format(Date, "yyyy-mm-dd") & ".xlsx", "H", "2\*"
GenerateFile ws, columns3, lastRow, filePath1 & "UPU41\_Cond\_" & Format(Date, "yyyy-mm-dd") & ".xlsx", "H", "2\*", "AK", "6.08", "28.58"
GenerateFile ws, columns5, lastRow, filePath1 & "UPU43\_Desc\_" & Format(Date, "yyyy-mm-dd") & ".xlsx", "H", "1\*", , , , True
GenerateFile ws, columns6, lastRow, filePath1 & "UPU43\_Cond\_" & Format(Date, "yyyy-mm-dd") & ".xlsx", "H", "1\*", , , , True
When columns2 runs, no filter is applied. Here are the results. We should only be seeing rows from the original file where the LIFNR column starts with a 2.
| WERKS |
MATNR |
LIFNR |
|
MH62D9VWP |
10081200 |
|
MH68D9VWP |
2SG02011 |
|
MH74D9VWP |
2US00080 |
|
MH80D9VWP |
2FR08021 |
|
MH86D9VWP |
10081200 |
|
MH92D9VWP |
10081200 |
When columns3 runs, the first filter works, but the secondary does not. The Results here do show LIFNR with a 2 but the KBETR column should not have a blank field.
| LIFNR |
EKORG |
KSCHL |
KBETR |
| 2SG02011 |
|
|
28.58 |
| 2US00080 |
|
|
|
| 2FR08021 |
|
|
6.08 |
For columns5 and columns6 variants, the results are the same from the columns2 variant, but in this case, they should only show the LIFNR that begin with a 1.
| YSRNO |
MATNR |
LIFNR |
| 1 |
|
MH62D9VWP |
| 2 |
|
MH68D9VWP |
| 3 |
|
MH74D9VWP |
| 4 |
|
MH80D9VWP |
| 5 |
|
MH86D9VWP |
| 6 |
|
MH92D9VWP |
Here is the output from the Debug on the columns2 and columns3 variants.
Row: 5 - FilterColumn: H - Value: 10081200 - Matches: False
FilterValue: 2*
SecondaryFilterValue1: - SecondaryFilterValue2:
Row 5 matches filter criteria.
Row: 6 - FilterColumn: H - Value: 2SG02011 - Matches: True
FilterValue: 2*
SecondaryFilterValue1: - SecondaryFilterValue2:
Row 6 matches filter criteria.
Row: 7 - FilterColumn: H - Value: 2US00080 - Matches: True
FilterValue: 2*
SecondaryFilterValue1: - SecondaryFilterValue2:
Row 7 matches filter criteria.
Row: 8 - FilterColumn: H - Value: 2FR08021 - Matches: True
FilterValue: 2*
SecondaryFilterValue1: - SecondaryFilterValue2:
Row 8 matches filter criteria.
Row: 9 - FilterColumn: H - Value: 10081200 - Matches: False
FilterValue: 2*
SecondaryFilterValue1: - SecondaryFilterValue2:
Row 9 matches filter criteria.
Row: 10 - FilterColumn: H - Value: 10081200 - Matches: False
FilterValue: 2*
SecondaryFilterValue1: - SecondaryFilterValue2:
Row 10 matches filter criteria.
Applying sensitivity label to: C:\Users\Desktop\UPU41_Desc_2025-01-02.xlsx
Sensitivity label applied successfully.
Saving file: C:\Users\Desktop\UPU41_Desc_2025-01-02.xlsx
Generating file: C:\Users\Desktop\UPU41_Cond_2025-01-02.xlsx
Row: 5 - FilterColumn: H - Value: 10081200 - Matches: False
Row: 5 - SecondaryFilterColumn: AK - Value: - Matches: 29
FilterValue: 2*
SecondaryFilterValue1: 6.08 - SecondaryFilterValue2: 28.58
Row 5 does not match filter criteria.
Row: 6 - FilterColumn: H - Value: 2SG02011 - Matches: True
Row: 6 - SecondaryFilterColumn: AK - Value: 28.58 - Matches: 29
FilterValue: 2*
SecondaryFilterValue1: 6.08 - SecondaryFilterValue2: 28.58
Row 6 matches filter criteria.
Row: 7 - FilterColumn: H - Value: 2US00080 - Matches: True
Row: 7 - SecondaryFilterColumn: AK - Value: - Matches: 29
FilterValue: 2*
SecondaryFilterValue1: 6.08 - SecondaryFilterValue2: 28.58
Row 7 matches filter criteria.
Row: 8 - FilterColumn: H - Value: 2FR08021 - Matches: True
Row: 8 - SecondaryFilterColumn: AK - Value: 6.08 - Matches: -1
FilterValue: 2*
SecondaryFilterValue1: 6.08 - SecondaryFilterValue2: 28.58
Row 8 matches filter criteria.
Row: 9 - FilterColumn: H - Value: 10081200 - Matches: False
Row: 9 - SecondaryFilterColumn: AK - Value: - Matches: 29
FilterValue: 2*
SecondaryFilterValue1: 6.08 - SecondaryFilterValue2: 28.58
Row 9 does not match filter criteria.
Row: 10 - FilterColumn: H - Value: 10081200 - Matches: False
Row: 10 - SecondaryFilterColumn: AK - Value: - Matches: 29
FilterValue: 2*
SecondaryFilterValue1: 6.08 - SecondaryFilterValue2: 28.58
Row 10 does not match filter criteria.
Applying sensitivity label to: C:\Users\Desktop\UPU41_Cond_2025-01-02.xlsx
Sensitivity label applied successfully.
Saving file: C:\Users\Desktop\UPU41_Cond_2025-01-02.xlsx
To me, it appears that the values that are entered into the variants for the filters are not being read properly. Looking at Row:5 from columns2, it shows the value of 100* and the match is false, but then the last line shows Row 5 matches filter criteria so everything is copied over.
Row: 5 - FilterColumn: H - Value: 10081200 - Matches: False
FilterValue: 2*
SecondaryFilterValue1: - SecondaryFilterValue2:
Row 5 matches filter criteria.
The reason this shows row 5 but you see row 1 above in the data, the file starts to copy from row 5.
I hope this helps a little with trying to figure out what is wrong.
Thank you