Forum Discussion
My VBA copies row if cell NOTBLANK but I need target columns in specific order (Code in post)
- Apr 26, 2024
Kenneth Green The <> operator on its own will only work if the cells in column K are truly blank. Since it's not working for you, I'm guessing the cells contain zero-length strings, most likely the result of a formula returning "". In this case, you can try using a formula as the criteria. There are 3 rules when using formulas in the criteria range:
- No heading (or use a custom heading not found in the data range, ie: "Criteria1").
- The formula must result in True or False.
- The formula should reference the first row of the data range.
So, in the "AdvFilter" worksheet, delete the heading in cell A1 (or use Criteria1 as the heading), then try either one of the following formulas in cell A2:
='Track Data'!K2<>"" //OR =TRIM('Track Data'!K2)<>"" //OR =LEN('Track Data'!K2)>0
Formula Criteria Example
To address the Advanced Filter results lingering afterwards, which can significantly increase the size of the file when dealing with large amounts of data, just add one line of code to clear the results (rgResults.Offset(1).ClearContents), immediately after the line of code that copies the results to an array:
'Copy the results to an array Dim rgResults As Range, n As Long Set rgResults = wsFilter.Range("A5").CurrentRegion n = rgResults.Rows.Count - 1 If n < 1 Then GoTo CleanUp Dim arr As Variant arr = rgResults.Offset(1).Resize(n).Value rgResults.Offset(1).ClearContents
If you have any other questions, let me know. Cheers!
Bad luck about the Excel 2019 bit! A later version and a worksheet formula would do the job.
= LET(
filtered, VSTACK(header, FILTER(table, Col.H<>"")),
DROP(SORTBY(filtered, {1,2,10,11,6,7,8,9,3,4,5}),,-2)
)