- Katılım
- 31 Aralık 2005
- Mesajlar
- 4,400
- Excel Vers. ve Dili
- Office 365 (64 bit) - Türkçe
Böyle durumlarda Regular Expressions (Düzenli ifadeler) izlenebilecek en iyi yoldur.
Aşağıda bir test ekledim.
Aşağıda bir test ekledim.
Kod:
Sub test()
Dim arr(1 To 4), reg As Object, colReg As Object, i As Integer
arr(1) = "Emine YALÇIN -(AKSOY)"
arr(2) = "Zeki GÜRSOY"
arr(3) = "Hüseyin"
arr(4) = "Levent / Menteşoğlu"
Set reg = CreateObject("VBScript.RegExp")
reg.Global = True
reg.Pattern = "[a-zA-ZIğĞüÜşŞİöÖçÇ]+([a-zA-ZIğĞüÜşŞİöÖçÇ]+)?"
For i = 1 To 4
Set colReg = reg.Execute(arr(i))
Select Case colReg.Count
Case 0
Debug.Print "["; arr(i); "]"
Debug.Print ">>> Ad/Soyad bulunamadı <<<"
Debug.Print ""
Case 1
Debug.Print "["; arr(i); "]"
Debug.Print "Adı : "; colReg(0)
Debug.Print ""
Case 2
Debug.Print "["; arr(i); "]"
Debug.Print "Adı : "; colReg(0); " -> Soyadı : "; colReg(1)
Debug.Print ""
Case 3
Debug.Print "["; arr(i); "]"
If colReg(i).submatches.Count = 0 Then
Debug.Print "Adı : "; colReg(0); " -> İkinci Adı : "; colReg(1); " -> Soyadı : "; colReg(2)
Else
Debug.Print "Adı : "; colReg(0); " -> Soyadı : "; colReg(1); " -> İkinci Soyadı : "; colReg(2)
End If
Debug.Print ""
Case Else
Debug.Print "["; arr(i); "]"
Debug.Print ">>> Tutarsız Ad/Soyad metni <<<"
Debug.Print ""
End Select
Next
End Sub
