0 votes
in VBA by Beginner (2 points)

I want to use your function ReplaceN  https://wellsr.com/vba/2016/excel/replace-Nth-occurrence-of-substring-in-string-with-vba/, but when i try to use it i get the Run-time error 438, at strM = str1. 
What can I do to make the code work? Is there a references that I need or something else? 

by Super Expert (3.2k points)
I'll be happy to help you out - no references are needed, so I suspect it's an error in how you're calling the function or what you're passing to the str1 variable (since str1 is a variant and strM is a string). To help you troubleshoot, please share how you're trying to call the function and what type of object str1 is.
by Beginner (2 points)
Yes, i realised that you're right and that I were using the Str1 variable wrong. Is it possible to use ReplaceN or something simular to replace words in a string, since I want to replace word in a text-file that I have converted into a string?
Best regards, Anna
by Super Expert (3.2k points)

I'm afraid I'll need a bit more information. If you converted the values in your text file to a string, the ReplaceN function will replace the words in that string. You'd then need to write the resulting string back to a text file. Here's a tutorial explaining how to write to a text file with VBA.

Please log in or register to answer this question.

Welcome to wellsr Q&A
wellsr Q&A is the VBA and Python programming community that rewards you for learning how to code.

Getting Started
VBA Cheat Sheets (On Sale Now)

Earn free prizes for asking VBA and Python questions and for answering questions asked by others in our community.

Looking for something else? Hire our professional VBA Help, instead.

What makes us different?
Our points system rewards you with a chance for free gifts based on the quality of your questions and answers. All you have to do is post and you could get rewarded, like these members:

ParserMonster $25 Amazon Gift Card
Hightree $10 Amazon Gift Card
Thales1 $10 Amazon Gift Card
runfunke $10 Amazon Gift Card
coolag $10 Amazon Gift Card
Siew Hun $10 Amazon Gift Card

So, why don't you join us? It really is an encouraging way to motivate members in our VBA and Python community.


For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.