vendredi 15 juillet 2016

VBA Type Mismatch when returning string to a value

Fairly new to VBA but I have the following function that runs up until the Workbooks(PDwb).Sheets("pivotdata").Range("E2").Value = "ON-HAND" then returns a Tpye Mismatch Error.

The full code checks a cell from a different workbook so I don't know if that is causing the error.

Function IfCheck(Cell As Variant)

    If Cell = "ON_HAND" Or Cell = "ON HAND" Then
        Set PDwb = ActiveWorkbook
        Workbooks(PDwb).Sheets("pivotdata").Range("E2").Value = "ON-HAND"
    Else
        Set PDwb = ActiveWorkbook
        Workbooks(PDwb).Sheets("pivotdata").Range("E2").Value = Cell
    End If

    Set BOwb = ActiveWorkbook

End Function

I can't for the life of me work out what to do differently :S

Many Thanks,

Aucun commentaire:

Enregistrer un commentaire