Replace function while using EXCELVBA

Hi,
 I am trying to use a replace function to replace a field's "," character with spaces. It gives me a compilation error saying Replace function not defined. is there any specific reference that I need to add for using replace functions?. I am using TRIM without any trouble. Can someone suggest any better alternative

Thanks
jibinptAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AzraSoundCommented:
Try specifying the VBA library as well, e.g.,

VBA.Replace(...)
0
PaultheGreatCommented:
try this out:

ThisWorkbook.Worksheets(1).Range("A1:J10").Replace ",", " ", xlPart, xlByRows

hope that helps!
-PtG
0
jibinptAuthor Commented:
This is my code
ReplacedDesc = Replace(lsProcessSheet.Cells(lrow, glDescCol), ",", " ")..  VBA.Replace is not working
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

AzraSoundCommented:
When you type in VBA and then hit the dot (.) does the list of available function calls come up?  Is Replace listed as one of them?
0
Tommy KinardCommented:
You need to add .Value
ReplacedDesc = Replace(lsProcessSheet.Cells(lrow, glDescCol).Value, ",", " ")

HTH
dragontooth

0
jibinptAuthor Commented:
When I type in VBA the dot (.) does come up but Replace is not one among them. RESET  is the only one which comes up with RE.
0
PaultheGreatCommented:
Replace(...) by itself isn't a valid function in VBA for Office 97... below is an excerpt from the Microsoft Excel Visual Basic help file:
------------------------------------

Syntax

expression.Replace(What, Replacement, LookAt, SearchOrder, MatchCase, MatchByte)

expression   Required. An expression that returns a Range object.

------------------------------------
Thus, "expression" is required, and generally you'll use this function as in my previous post. If you want to just replace values in a normal string without using Ranges and whatnot, you'll have to write your own little Replace function, as below:

Public Function replaceStr(ByVal str1 As String, ByVal repThis As String, ByVal withThis As String) As String
    While Left(str1, Len(repThis)) = repThis
        str1 = withThis & Mid(str1, Len(repThis) + 1)
    Wend
    While InStr(2, str1, repThis) > 0
        i = InStr(2, str1, repThis)
        str1 = Left(str1, i - 1) & withThis & Mid(str1, i + Len(repThis))
    Wend
    replaceStr = str1
End Function

hope that helps!
-PtG
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AzraSoundCommented:
Oh, is this VBA 97?  Replace didnt come around until VB6, so I guess that would mean VBA 2000?
0
Tommy KinardCommented:
Are you getting an error on the replace line or is it just not working?

dragontooth

0
PaultheGreatCommented:
thanks for the points and the A! time to go home now... happy programming, people!

Regards,
PtG
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.