Thread: [Solved] passing values in function
View Single Post
 
Old 04-17-2022, 11:01 PM
Bikram Bikram is offline Windows 10 Office 2007
Advanced Beginner
 
Join Date: Jul 2021
Location: Nepal
Posts: 94
Bikram is on a distinguished road
Default passing values in function

Hi all members, I am working on a macro where i encountered an error
Code:
Function newreplace(rng2) As Range
Dim e(), f()
e = Array("( ){2,}", "^s", Chr(160), "^t{2,}", "(\([a-z]\)){1,4}")
f = Array("\1", " ", " ", "^t", "\1")
Dim i As Integer
For i = LBound(e) To UBound(e)
With rng2.find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = e(i)
    .Replacement.Text = f(i)
    .MatchWildcards = True
    .Wrap = wdFindStop
End With
rng2.find.Execute Replace:=wdReplaceAll
Next
End Function
Here everything seems to work fine but when I reached the "with rng2.find" line VBA throws an error "424". I couldn't get a hint What did I miss? It would be a great help if someone points out what am I doing wrong and suggests a solution.
Reply With Quote