Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #4  
Old 01-10-2024, 08:17 AM
syl3786 syl3786 is offline Find and replace the number format after vbTab Windows 10 Find and replace the number format after vbTab Office 2019
Advanced Beginner
Find and replace the number format after vbTab
 
Join Date: Jan 2023
Posts: 97
syl3786 is on a distinguished road
Default

Quote:
Originally Posted by vivka View Post
Hi, syl3786! Or you can use:
Code:
Sub Repl_Digits_W__Wds_3()
'In selected paragraphs, replace the digits that start tabbed paras with wds.

Dim para As Paragraph
Dim dgt As range

Application.ScreenUpdating = False
    For Each para In selection.range.Paragraphs
'Search for only digits:
        If para.range.Characters(1) = Chr(9) And _
            para.range.Characters(2) Like "[0-9]" And _
            para.range.Characters(3) = Chr(32) Then
                Set dgt = para.range.Characters(2)
                Select Case dgt
                    Case "0"
                        dgt = "zero"
                    Case "1"
                        dgt = "one"
                    Case "2"
                        dgt = "two"
                    Case "3"
                        dgt = "three"
                    Case "4"
                        dgt = "four"
                    Case "5"
                        dgt = "five"
                    Case "6"
                        dgt = "six"
                    Case "7"
                        dgt = "seven"
                    Case "8"
                        dgt = "eight"
                    Case "9"
                        dgt = "nine"
                End Select
        End If
    Next para
Application.ScreenUpdating = True
End Sub
Thank you for your response. I appreciate your effort. However, I would like to bring to your attention that there seems to be an error "5941" when running the macro due to these three lines of code:

Code:
If para.range.Characters(1) = Chr(9) And _
 para.range.Characters(2) Like "[0-9]" And _
 para.range.Characters(3) = Chr(32) Then
I managed to resolve it by using vbTab instead of Chr(9) and by employing the use of case. Thank you for your attention to this matter.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't find and replace (Appendix + any number) Muse1 Word 1 12-30-2023 08:36 AM
Find and replace the number format after vbTab find and replace with format karkey Word VBA 2 08-02-2022 03:04 PM
Find/Replace using format of cell catflap Excel 1 09-11-2017 07:28 AM
Find and replace the number format after vbTab Need Help to Find a Number and replace Allen Word 5 11-20-2014 10:33 PM
Find and replace the number format after vbTab Find and Replace maintain format winningson Word 3 01-19-2013 05:38 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:21 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft