codice:
Function isCodFis(ByVal szCFPI As String) As Integer
            Dim nLen As Integer
            Dim i As Integer
            Dim n As Integer
            Dim nRetVal As Integer
            Dim s As String

            nRetVal = 0 ' default Partita IVA 
            nLen = Len(szCFPI)

            For i = 1 To nLen
                s = Mid(szCFPI, i, 1)
                n = Asc(s)
                If n <> 32 Then
                    If (n > 47 And n < 58) Then ' se numerico 
                        nRetVal = 0 ' partita iva 
                    Else
                        nRetVal = 1 ' altrimenti codice fiscale 
                    End If ' 
                    Exit For
                End If
            Next
            Return nRetVal
        End Function

spero che ti basti...