我只用vba Function f(a As String) As String Dim i As Integer, j As Integer, k As Byte Dim gg As Variant gg = Array("直营", "代理", "总部") k = 0 For i = 1 To Len(a) - 1 For j = 0 To 2 If Mid(a, i, 2) = gg(j) Then f = gg(j) k = 1 Exit For End If Next j If k = 1 Then Exit For Next i End Function