Have a look down-below, perhaps it gives you clue.
Nevertheless, I will try to comment the details to get you acquainted closely with the matter.
My example is a bit more complicated because it applies filtering on two columns at once, but it is good for you understand it as complicated as it is because you can further apply it.
With Sheets("Source")
.AutoFilterMode = False
With .Range("$A$21" & ":" & "$C$" & 300)
.AutoFilter Field:=1, Criteria1:=Array("April", "August", "Dezember", "Februar", "Januar", "Juli", "Juni", "Mai", "März", "November", "Oktober", "September"), Operator:=xlFilterValues
.AutoFilter Field:=2, Criteria1:="<>"
ActiveSheet.AutoFilter.Range.Copy
Sheets("Chart").Select
Range("A7").Select
Sheets("Chart").Paste
End With
End With
So, what is this about:
logic of the code is
- filter on two columns columns 1 by the name of the Months (i.e. German language), column 2 filter the elements by eliminating the cells which are blanks/empty
With Sheets("Source")
.AutoFilterMode = False
With .Range("$A$21" & ":" & "$C$" & 300)
.AutoFilter Field:=1, Criteria1:=Array("April", "August", "Dezember", "Februar", "Januar", "Juli", "Juni", "Mai", "März", "November", "Oktober", "September"), Operator:=xlFilterValues
.AutoFilter Field:=1, Criteria1:=Array("April", "August", "Dezember", "Februar", "Januar", "Juli", "Juni", "Mai", "März", "November", "Oktober", "September"), Operator:=xlFilterValues
column 2
.AutoFilter Field:=2, Criteria1:="<>"
- last, but not least (very important) is the Range ( the cells of the tables to which the filtering is applied)
With .Range("$A$21" & ":" & "$C$" & 300)
in this case my example applies the filter to a range of cells( as a matter a fact a table) that starts with A21 and ends up at C300.
why A21? Because that's where my data gets copied. It starts from A21 always.
why C300? Because the maximum number of rows will never exceed (300-21)=279 rows
my model of data is not exceeding 279 of unfiltered rows at any time, you can put a greater figure as per your assumption.
If there are more rows, nevermind because I filtered them by eliminating the blanks , see above.
By the way, the "kosher" version is to count the number of rows via VBA and use this when defining your range.
You can simply use a very large number that covers the possible number of rows in your table.
Counting the number of rows this might be a bit complicated for you at the 1st glance, but shall pay its pennies in the end.
supposedly you want to count the number of rows (variable) in Column B
FinalRowChartSheet = Range("B7").End(xlDown).Row
Wish you the best. I hope I helped you.
Do not forget to rate my answer if you find it useful.Thank you.