mardi 18 août 2020

loop through #N/A in a column and insert a formula over all #N/A

So I have a column with close to 100k entries. I want to loop through every #N/A in the column and replae the #N/A with a formula. I got the finding of #N/A and the formula- inserting working fine but I seem to have a mistake in my loop, which I don´t get. My Code looks like this

Sub Tes()
Dim findrow As Double
Dim lstrow As Double
Dim row As Double
Dim length As String
Dim emp As Variant
Dim Err As String

Err = "#N/A"
emp = " "
row = 1
lstrow = Range("G" & Rows.Count).End(xlUp).row



Workbooks("OCC_index(Test)").Activate


For row = 1 To lstrow
    If IsError(ActiveWorkbook.Sheets("OCC").Range("F1").Offset(offsetCount, 0).value) Then
        If (ActiveWorkbook.Sheets("OCC").Range("F1").Offset(offsetCount, 0).value <> Err) Then
            findrow = global_searchByRow_inCol("#N/A", Workbooks("OCC_index(Test)"), 6)
        End If
    End If
        If Not findrow = 0 Then
            Cells(findrow, 6).formula = "=IF(ISNA(INDEX(august.csv!$C:$C,MATCH(R" & findrow & ",august.csv!$D:$D,0)))= TRUE," & emp & ",(INDEX(august.csv!$C:$C,MATCH(R" & findrow & ",august.csv!$D:$D,0))))"
        End If

Next row

I get the error type mismatch in line

If Range("F" & row) = Err Then

It´s the correct row but it doens´t execute Then. If I debugg and put it one line down manually, it runs perfectly again until the next #N/A. What am I not getting here?

Edit: I edited the question with the edited code. I also tried .text instead of .value

Aucun commentaire:

Enregistrer un commentaire