Improving Macro That Keeps First Letter

Pin

Joined
Nov 23, 2020
Messages
2
Reaction score
0
I found this code that works for my purpose of deleting every letter except the first letter. However, I am applying this automation to bible verses, and I do not want the verse numbers to be tampered with. My problem is that the current code will shorten "10" to "1" and "11" to "1" or "25" to "2" and so on. I've tried adding Select Case to omit double digits, but does not seem to do what I intend. What am I doing wrong?

Bonus: Current code is sub-optimal, as it replaces letters with a space " ", instead of deleting. I work around it by doing find & replace (find spaces. Find line breaks. Then replace with delete). When I tried to record a macro while doing this find and replace, the recorded actions only consisted of "open side window". But if the spaces and line breaks can be handled in code too, that would be better.

Here is the portion of working code:

Sub Macro1()
'
' Macro1 Macro
'
'
Dim oWord As Word.Range
For Each oWord In ActiveDocument.Range.words
For i = 2 To oWord.Characters.Count
If Not oWord.Characters(i) = " " Then
oWord.Characters(i) = " "
End If
Next i
Next oWord
End Sub

And here is my attempt to save the double digits from being touched:
Sub DeleterF()
'
' DeleterF Macro
'
'
Dim oWord As Word.Range
For Each oWord In ActiveDocument.Range.words
Select Case oWord
Case "10", "11", "12", "13"
Debug.Print "Confirm Case of DoubleDigits"
Case Else
For i = 2 To oWord.Characters.Count
If Not oWord.Characters(i) = " " Then
oWord.Characters(i) = " "
End If
Next i
End Select
Next oWord
End Sub

If it helps at all, my Debug.Print message does not print in the "Immediate" window.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top