I’m not quite sure I understood your question, but if you want to leave the variable range according to your filter result, you can replace it:
Destination:=Range("C2:C329")
for:
Destination:=Range(Selection, Selection.End(xlDown))
Thus, all cells below the active reference will always be selected.
NOTE: I’m assuming you don’t have any blank lines in your selection, as it will be filtered.
edited
if you want to replace cells that have #N/D in a column you can use the following approach:
Note that I am using On Error Resume Next
which is not recommended, but it solves your problem by the hour. If you can think of something to circumvent the incompatibility when the code compares "" to an Error it would be a good improvement.
Sub replaceNAs()
On Error Resume Next 'quando a macro encontrar #N/D o valor não é comparável com "",
Dim offsetCount As Integer
Dim ref As Range: Set ref = Range("C2") ' célula de referência
offsetCount = 0 'valor do offset
While Not ref.Offset(offsetCount, 0).Value = "" 'enquanto o valor da célula não for vazio
If Application.WorksheetFunction.IsNA(ref.Offset(offsetCount, 0).Value) Then 'caso seja #N/D
If ref.Offset(offsetCount, 0).Value = CVErr(xlErrNA) Then
ref.Offset(offsetCount, 0).FormulaR1C1 = ref.FormulaR1C1 'a célula atual recebe a fórmula da célula de referencia
End If
End If
offsetCount = offsetCount + 1
Wend
End Sub
I suggest using Excel tables to make your life easier in this case and work with them. I could filter everything you have
#N/D
and run your code easily using the following module: https://github.com/evertramos/excel-modules/blob/master/m_TableFunctions.bas. which has several functions to work with Excel Tables.– Evert