If, like the question states, you are only interested in excluding #REF!
errors, this is the correct check:
For Each akt_range In Range("C3:J65")
If CStr(akt_range.Value2) <> CStr(CVErr(xlErrRef)) Then
akt_range.Value = akt_range.Value2
End If
Next
Technically, the above will fail in the very special case of a formula returning the error code string for #REF!
exactly, e.g., ="Error 2023"
. The absolutely bulletproof check is this:
For Each akt_range In Range("C3:J65")
If Not IsError(akt_range.Value2) Or CStr(akt_range.Value2) <> CStr(CVErr(xlErrRef)) Then
akt_range.Value = akt_range.Value2
End If
Next
If you wish to exclude all errors, a better solution would be to use .SpecialCells()
to eliminate the errors from the range before looping:
For Each akt_range In Range("C3:J65").SpecialCells(xlCellTypeFormulas, xlLogical + xlNumbers + xlTextValues)
akt_range.Value = akt_range.Value2
Next