Andrewz, some of these answers are elegant indeed, but have you posed the right question?
As a student, I spent a wonderful year in Innsbruck on a street called Schneeburggasse. Delightful though my neighbours were, I'm sure they'd turn their noses up at their street becoming Schneeburggaße. Likewise, my German pen pal used to live on a road called Schloßstraße - if that is recorded in your database as Schlossstrasse, then wouldn't Schlossstraße look a little odd?
My point is that just doing a replace of the last ss could give you some very strange results. Short of writing an incredibly complex morpheme analysis programme to apply the already flaky Eszett rules, you're going to need a more reliable workaround.
I'd suggest creating a collection of common names, like Straße, Schloß, etc. that you can be sure need to be replaced. Run a replace on those and then store any other occurrences of ss for you to loop through and check manually. Something like the code below:
Option Explicit
Private mCommonWords As Collection
Private mAmbiguous As Collection
Public Sub RunMe()
Dim str As String
Dim cell As Range
CreateCommonWordList
ReplaceOrNote
' Do anything you like with the list of ambiguous cells
For Each cell In mAmbiguous
str = str & cell.Address(False, False) & vbLf
Next
MsgBox str
End Sub
Private Sub CreateCommonWordList()
Set mCommonWords = New Collection
AddCommonWord "straße", "strasse"
AddCommonWord "straße", "str."
AddCommonWord "schloß", "schloss"
End Sub
Private Sub AddCommonWord(correct As String, wrong As String, Optional capitalise As Boolean = True)
Dim words(1) As String
Dim splitCorrect(1) As String
Dim splitWrong(1) As String
words(0) = correct
words(1) = wrong
mCommonWords.Add words
If capitalise Then
splitCorrect(0) = UCase(Left(correct, 1))
splitCorrect(1) = Mid(correct, 2, Len(correct) - 1)
correct = splitCorrect(0) & splitCorrect(1)
splitWrong(0) = UCase(Left(wrong, 1))
splitWrong(1) = Mid(wrong, 2, Len(wrong) - 1)
wrong = splitWrong(0) & splitWrong(1)
words(0) = correct
words(1) = wrong
mCommonWords.Add words
End If
End Sub
Private Sub ReplaceOrNote()
Dim ws As Worksheet
Dim v As Variant
Dim startCell As Range
Dim foundCell As Range
Set ws = ThisWorkbook.Worksheets("Sheet1")
' First replace the common words
For Each v In mCommonWords
ws.Cells.Replace _
What:=v(1), _
Replacement:=v(0), _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=True, _
SearchFormat:=False, _
ReplaceFormat:=False
Next
' Now search for every other 'ss' member
Set mAmbiguous = New Collection
Set startCell = ws.Cells.Find( _
What:="ss", _
After:=ws.Cells(ws.Rows.Count, ws.Columns.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=True)
If Not startCell Is Nothing Then
mAmbiguous.Add startCell
Set foundCell = startCell
Do
Set foundCell = ws.Cells.FindNext(foundCell)
If foundCell Is Nothing Then
Exit Do
ElseIf foundCell.Address = startCell.Address Then
Exit Do
Else
mAmbiguous.Add foundCell
End If
Loop While True
End If
End Sub
Hi Ambie I know Innsbruck is beautiful... your code is it too. My problem is I must load up street addresses, postcode and so on too Webfleet. That is a online portal (in german) for tracking service cars (Geoposition). If I upload the daily service tour on the driver terminal TomTom 8275 the excel tool for do that reports often errors (on Geocoding) if the streetname ends with strasse. Another problem many adresses rows in the excel worksheets ends with str. (Innsbruckerstr.). So that i must replace this to Insbruckerstraße. I have test your code and he solve both problems. But on Strasserstr. he change it to Straßerstraße i think because the letter series strasse is in strasser. OK i can live with that...thanks again