Sau đây chúng tôi xin giới thiệu hàm tách họ tên trong Excel mời bạn đọc tham khảo. Đầu tiên bạn có thể sử dụng các hàm có sẵn trong Microsoft Excel để thực hiện yêu cầu. Ví dụ dưới đây là 2 hàm tách tên, họ+chữ lót.

Function ExtractFirstName(strFullName As String) As String Dim strTemp As String Dim i As Integer Dim l As Integer strTemp = strFullName l = Len(strFullName) If l > 0 Then i = 0 If InStr(1, strFullName, " ", vbTextCompare) Then Do i = i + 1 Loop Until Mid(strFullName, l - i, 1) = " " strTemp = Right(strFullName, i) Else End If Else strTemp = "" End If ExtractFirstName = strTemp End Function Function ExtractLastMiddleName(strFullName As String) As String Dim strTemp As String Dim i As Integer Dim l As Integer strTemp = strFullName l = Len(strFullName) i = 0 If InStr(1, strFullName, " ", vbTextCompare) Then Do i = i + 1 Loop Until Mid(strFullName, l - i, 1) = " " strTemp = Left(strFullName, l - i) Else strTemp = "" End If ExtractLastMiddleName = strTemp End Function
Theo pcworld
Bạn đang muốn nâng cao kỹ năng lập trình của mình ?
|












