17.01.2023, 18:21
Hallo zusammen,
ich habe mir heute einen VBA für die Geschlechteridentifikation von Vornamen gesucht und bin dabei auf folgenden Code gestoßen:
Function mw(sName As String)
'Umsetzung von
'http://www.herber.de/excelformeln und bitte suchen .../formeln.html?welcher=430
'in Code
'WF habe Gnade mit mir
Dim sm(2 To 6), sw(1 To 6), sms, sws
If sName = "" Then
mw = ""
Else
Select Case LCase(Right(sName, 2))
Case "ai", "an", "ay", "dy", "en", "fa", "gi", "hn", "nn", "oy", "pe", _
"ri", "ry", "ua", "uy", "ve", "we"
sm(2) = 1
End Select
Select Case LCase(Right(sName, 3))
Case "ael", "ali", "ain", "bal", "bin", "cal", "cca", "cel", "cin", _
"die", "don", "dre", "ede", "emy", "eon", "gon", "gun", "hel", _
"hka", "iel", "ill", "ini", "kie", "lge", "lon", "lte", "met", _
"mil", "min", "mon", "mud", "nsi", "oah", "obi", "oel", "örn", _
"ole", "oni", "rel", "rge", "ron", "rne", "rre", "rti", "son", _
"ste", "tie", "ton", "uce", "udi", "uel", "uli", "uke", "vid", _
"vin", "win", "xel"
sm(3) = 1
End Select
Select Case LCase(Right(sName, 4))
Case "abel", "akim", "kola", "eike", "eith", "elin", "frid", "gary", _
"hane", "hein", "irin", "mike", "muth", "neth", "ntin", "nuth", _
"önke", "ören", "rene", "rtin", "stas", "tila", "tony", "tore"
sm(4) = 1
End Select
Select Case LCase(Right(sName, 5))
Case "astel", "laude", "dolin", "ronny", "ustel", "ustin", "willi", "willy"
sm(5) = 1
End Select
Select Case LCase(Right(sName, 6))
Case "sascha"
sm(6) = 1
End Select
sms = -Application.Sum(sm)
Select Case LCase(Right(sName, 1))
Case "a", "e", "i", "n", "y"
sw(1) = 1
End Select
Select Case LCase(Right(sName, 2))
Case "ah", "al", "bs", "dl", "el", "et", "id", "il", "it", "ll", "th", _
"ud", "uk"
sw(2) = 1
End Select
Select Case LCase(Right(sName, 3))
Case "ary", "aut", "des", "een", "fer", "got", "ies", "ild", "ind", "jam", _
"ken", "kim", "lar", "len", "lis", "men", "mor", "oan", "ren", "res", _
"rix", "san", "tas", "udy", "urg"
sw(3) = 1
End Select
Select Case LCase(Right(sName, 4))
Case "atie", "borg", "cole", "gard", "gart", "gnes", "gund", "iede", "indy", _
"ines", "iris", "istl", "ldie", "lilo", "lott", "lynn", "oldy", "riam", _
"rien", "smin", "ster", "uste", "vien"
sw(4) = 1
End Select
Select Case LCase(Right(sName, 5))
Case "achel", "agmar", "almut", "doris", "edwig", "heike", "irene", "mandy", _
"meike", "rauke", "reike", "sandy", "sther", "uriel", "velin"
sw(5) = 1
End Select
Select Case LCase(Right(sName, 6))
Case "irsten", "almuth"
sw(6) = 1
End Select
sws = Application.Sum(sw)
If sws + sms = 1 Then
mw = "w"
Else
mw = "m"
End If
End If
End Function
Ich habe es bereits geschafft, das Modul in dem xlsm File anzulegen, jedoch verstehe ich nicht, wie ich den Code im Excel Sheet zum Laufen bekomme. Die Spalte meiner Vornamen heißt bereits sName und die Zielspalte ebenso mw. Habe ich einen Denkfehler, oder sollte der Code funktionieren? Bzw. muss ich den irgendwie gesondert starten?
Aktuell sind meine Spalten wie folgt sortiert:
Ticketname Bestellnummer Nachname sName mw Alter PLZ Stadt Land
Ich hoffe die Frage ergibt Sinn...
Vielen Dank im Voraus
LG
Jakob
ich habe mir heute einen VBA für die Geschlechteridentifikation von Vornamen gesucht und bin dabei auf folgenden Code gestoßen:
Function mw(sName As String)
'Umsetzung von
'http://www.herber.de/excelformeln und bitte suchen .../formeln.html?welcher=430
'in Code
'WF habe Gnade mit mir
Dim sm(2 To 6), sw(1 To 6), sms, sws
If sName = "" Then
mw = ""
Else
Select Case LCase(Right(sName, 2))
Case "ai", "an", "ay", "dy", "en", "fa", "gi", "hn", "nn", "oy", "pe", _
"ri", "ry", "ua", "uy", "ve", "we"
sm(2) = 1
End Select
Select Case LCase(Right(sName, 3))
Case "ael", "ali", "ain", "bal", "bin", "cal", "cca", "cel", "cin", _
"die", "don", "dre", "ede", "emy", "eon", "gon", "gun", "hel", _
"hka", "iel", "ill", "ini", "kie", "lge", "lon", "lte", "met", _
"mil", "min", "mon", "mud", "nsi", "oah", "obi", "oel", "örn", _
"ole", "oni", "rel", "rge", "ron", "rne", "rre", "rti", "son", _
"ste", "tie", "ton", "uce", "udi", "uel", "uli", "uke", "vid", _
"vin", "win", "xel"
sm(3) = 1
End Select
Select Case LCase(Right(sName, 4))
Case "abel", "akim", "kola", "eike", "eith", "elin", "frid", "gary", _
"hane", "hein", "irin", "mike", "muth", "neth", "ntin", "nuth", _
"önke", "ören", "rene", "rtin", "stas", "tila", "tony", "tore"
sm(4) = 1
End Select
Select Case LCase(Right(sName, 5))
Case "astel", "laude", "dolin", "ronny", "ustel", "ustin", "willi", "willy"
sm(5) = 1
End Select
Select Case LCase(Right(sName, 6))
Case "sascha"
sm(6) = 1
End Select
sms = -Application.Sum(sm)
Select Case LCase(Right(sName, 1))
Case "a", "e", "i", "n", "y"
sw(1) = 1
End Select
Select Case LCase(Right(sName, 2))
Case "ah", "al", "bs", "dl", "el", "et", "id", "il", "it", "ll", "th", _
"ud", "uk"
sw(2) = 1
End Select
Select Case LCase(Right(sName, 3))
Case "ary", "aut", "des", "een", "fer", "got", "ies", "ild", "ind", "jam", _
"ken", "kim", "lar", "len", "lis", "men", "mor", "oan", "ren", "res", _
"rix", "san", "tas", "udy", "urg"
sw(3) = 1
End Select
Select Case LCase(Right(sName, 4))
Case "atie", "borg", "cole", "gard", "gart", "gnes", "gund", "iede", "indy", _
"ines", "iris", "istl", "ldie", "lilo", "lott", "lynn", "oldy", "riam", _
"rien", "smin", "ster", "uste", "vien"
sw(4) = 1
End Select
Select Case LCase(Right(sName, 5))
Case "achel", "agmar", "almut", "doris", "edwig", "heike", "irene", "mandy", _
"meike", "rauke", "reike", "sandy", "sther", "uriel", "velin"
sw(5) = 1
End Select
Select Case LCase(Right(sName, 6))
Case "irsten", "almuth"
sw(6) = 1
End Select
sws = Application.Sum(sw)
If sws + sms = 1 Then
mw = "w"
Else
mw = "m"
End If
End If
End Function
Ich habe es bereits geschafft, das Modul in dem xlsm File anzulegen, jedoch verstehe ich nicht, wie ich den Code im Excel Sheet zum Laufen bekomme. Die Spalte meiner Vornamen heißt bereits sName und die Zielspalte ebenso mw. Habe ich einen Denkfehler, oder sollte der Code funktionieren? Bzw. muss ich den irgendwie gesondert starten?
Aktuell sind meine Spalten wie folgt sortiert:
Ticketname Bestellnummer Nachname sName mw Alter PLZ Stadt Land
Ich hoffe die Frage ergibt Sinn...
Vielen Dank im Voraus
LG
Jakob