Формирует винительный падеж фамилии, имени, отчества.
=AccusativeCase(A1), =AccusativeCase(A1;B1;C1), =AccusativeCase(A1;B1), где:
• sSurname - фамилия;
• sName - имя;
• sPatronymic - отчество.
Option Compare Text 'сравнение без учета регистра
Function AccusativeCase(sSurname$, Optional sName$, Optional sPatronymic$) As String
Application.Volatile True 'автопересчет формулы на листе
sSurname$ = Replace(sSurname$, " - ", "-"): sSurname$ = Replace(Replace(sSurname$, " -", "-"), "- ", "-")
On Error Resume Next
If sName$ = "" And sPatronymic$ = "" Then
arr = Split(Application.Trim(sSurname$))
sSurname$ = arr(0): sName$ = arr(1): sPatronymic$ = Replace(arr(2), ".", "")
End If
'заканчивается на "вна" или "кызы" - женщины, остальные - мужчины
Dim bMaleSex As Boolean: 'bMaleSex = (Right(sPatronymic, 1) = "ч" Or Right(sPatronymic, 4) = "оглы")
bMaleSex = Not (Right(sPatronymic, 2) = "на" Or Right(sPatronymic, 4) = "кызы")
If Len(sSurname) > 0 Then 'фамилия
arrSurname = Split(sSurname, "-")
For i = LBound(arrSurname) To UBound(arrSurname) 'перебираем все части фамилий, содержащих дефис
sRes = "": sSurnamePart = arrSurname(i)
If bMaleSex Then 'мужские фамилии
Select Case Right(sSurnamePart, 1)
Case "о", "и", "ы", "у", "э", "е", "ю": sRes = sSurnamePart
Case "й": sRes = Mid(sSurnamePart, 1, Len(sSurnamePart) - 2) & "ого"
Case "ь": sRes = Mid(sSurnamePart, 1, Len(sSurnamePart) - 1) & "я"
Case "я": sRes = Mid(sSurnamePart, 1, Len(sSurnamePart) - 1) & "ю"
Case "а": sRes = Mid(sSurnamePart, 1, Len(sSurnamePart) - 1) & "у"
If UBound(arrSurname) > 0 And i = 0 Then sRes = sSurnamePart
Case Else: sRes = sSurnamePart & "а"
End Select
Select Case Right(sSurnamePart, 2) 'добавлено для редких фамилий
Case "ец": sRes = Mid(sSurnamePart, 1, Len(sSurnamePart) - 2) & "ца"
If LCase(sSurnamePart) Like "*[уеыаоэяиюё]ец" Then sRes = Mid(sSurnamePart, 1, Len(sSurnamePart) - 1) & "ца"
If LCase(sSurnamePart) Like "*[!уеыаоэяиюё][!уеыаоэяиюё]ец" Then sRes = sSurnamePart & "а"
Case "зе", "их", "ых": sRes = sSurnamePart
Case "ий", "ой": sRes = Mid(sSurnamePart, 1, Len(sSurnamePart) - 2) & "ого"
If Len(sSurnamePart) <= 4 Then sRes = Mid(sSurnamePart, 1, Len(sSurnamePart) - 1) & "я"
If Right(sSurnamePart, 3) = "чий" Then sRes = Mid(sSurnamePart, 1, Len(sSurnamePart) - 2) & "его"
Case "уй": sRes = Mid(sSurnamePart, 1, Len(sSurnamePart) - 2) & "уя"
Case "ей": sRes = Mid(sSurnamePart, 1, Len(sSurnamePart) - 2) & "ея"
End Select
Else 'женские фамилии
Select Case Right(sSurnamePart, 1)
Case "о", "е", "э", "и", "ы", "у", "ю", "б", "в", "г", "д", "ж", "з", "к", "л", "м", "н", "п", _
"р", "с", "т", "ф", "х", "ц", "ч", "ш", "щ", "ь", "й": sRes = sSurnamePart
Case "а": sRes = Mid(sSurnamePart, 1, Len(sSurnamePart) - 1) & "у"
Case "я": sRes = Mid(sSurnamePart, 1, Len(sSurnamePart) - 2) & "ю"
Case Else: sRes = Mid(sSurnamePart, 1, Len(sSurnamePart) - 1) & "у"
End Select
Select Case Right(sSurnamePart, 2) 'добавлено для редких фамилий
Case "ха": sRes = Mid(sSurnamePart, 1, Len(sSurnamePart) - 2) & "ху"
Case "ла": sRes = Mid(sSurnamePart, 1, Len(sSurnamePart) - 2) & "лу"
Case "ая": sRes = Mid(sSurnamePart, 1, Len(sSurnamePart) - 2) & "ую"
End Select
End If
' не склоняются мужские и женские фамилии, оканчивающиеся на -о, -е, -э, -и, -ы, -у, -ю,
'а также на -а с предшествующей гласной
If LCase(sSurnamePart) Like "*[уеыаоэяиюё]а" Then sRes = sSurnamePart
arrSurname(i) = sRes
Next
AccusativeCase = Join(arrSurname, "-") & " " 'соединяем части склоняемой фамилии обратно в одну строку
End If
If Len(sName) > 0 Then 'имя
NameException$ = GetAccusativeException(sName)
If Len(NameException$) Then 'для имен-исключений
AccusativeCase = AccusativeCase & NameException$
Else 'имя не найдено в списке исключений
If bMaleSex Then
Select Case Right(sName, 1)
Case "й", "ь": AccusativeCase = AccusativeCase & Mid(sName, 1, Len(sName) - 1) & "я"
Case "а": AccusativeCase = AccusativeCase & Mid(sName, 1, Len(sName) - 1) & "у"
Case "я": AccusativeCase = AccusativeCase & Mid(sName, 1, Len(sName) - 1) & "ю"
Case "о", "и": AccusativeCase = AccusativeCase & sName
Case Else: AccusativeCase = AccusativeCase & sName & "а"
End Select
Else
Select Case Right(sName, 1)
Case "а": AccusativeCase = AccusativeCase & Mid(sName, 1, Len(sName) - 1) & "у"
Case "я": AccusativeCase = AccusativeCase & Mid(sName, 1, Len(sName) - 1) & "ю"
Case Else: AccusativeCase = AccusativeCase & sName
End Select
End If
End If
AccusativeCase = AccusativeCase & " "
End If
If Len(sPatronymic) > 0 Then 'отчество
If Right(sPatronymic, 4) = "оглы" Or Right(sPatronymic, 4) = "кызы" Then
AccusativeCase = AccusativeCase & sPatronymic
Else
If bMaleSex Then
AccusativeCase = AccusativeCase & sPatronymic & "а"
Else
AccusativeCase = AccusativeCase & Mid(sPatronymic, 1, Len(sPatronymic) - 1) & "у"
End If
End If
End If
AccusativeCase = Replace(AccusativeCase, "-", "- ")
AccusativeCase = StrConv(AccusativeCase, vbUnicode + vbProperCase)
AccusativeCase = Trim(Replace(AccusativeCase, "- ", "-"))
End Function
Function GetAccusativeException(ByVal txt$) As String 'склонение имен-исключений
Select Case txt$
Case "Павел": GetAccusativeException = "Павла"
Case "Лев": GetAccusativeException = "Льва"
Case "Пётр": GetAccusativeException = "Петра"
Case "Петр": GetAccusativeException = "Петра"
Case "Любовь": GetAccusativeException = "Любовь"
Case "Ольга": GetAccusativeException = "Ольгу"
'без изменения (не склоняются) - перечисляем через запятую
Case "Али", "Бали": GetAccusativeException = txt$
End Select
End Function