How can I find a word with a new line in the VBA editor using find and replace?

Viewed 147

I would like to go through and find all of the "End" statements in my code but skipping all of the "End x" statements like "End If", "End Sub", "End function", etc.--Just the pure "End". My thought was to use pattern matching, but I am unsure of how to do that.

I already tried using "End\n" and "End[\n]".

VBE search box example

Does anyone know how to search for words that end in new lines?

2 Answers

The "find" function in the VBA editor does not support this kind of parameter/functionality.

You will have to manually step through the results and skip the ones you don't want to skip, or manually modify the "End" instances you don't want to catch, then search & replace, and finally restore all the End instances back to what you want.

Apologies for answering so long after the question was asked, but thought this information would help future readers as this question is still being actively found.

@TylerH is right that the specific search requested by the user cannot be performed in the VBE Find tool. For information, when "Use Pattern Matching" is selected the VBE Find tool supports use of:

? - single character

* - zero or more characters (on the same line)

# - single digit (0 to 9)

[charlist] - any single character in charlist

[!charlist] - any single character not in charlist

... where charlist can be a range of characters (eg [A-Z]) but must be in order (eg [Z-A] is not valid), it can also include multiple ranges of characters (eg [A-BD-E] matches A, B, D or E). Also to match any of ?, * or # then enclose them in square brackets (eg [*] matches an asterisk).

This means the VBE Find tool performs very similarly (perhaps identically ... but I can't provide assurances, VB and VBA not being the same language) to the VB Like operator, for which documentation is here

The alternative (which will perform the specific search in the question) is to use the 'Find Text' tool in the VBE Add-In MZ-Tools - though note MZ-Tools is a paid-for tool ... please note I am NOT in any way associated with MZ-Tools or it's author. The search text to use in MZ-Tools for the specific search requested in the question is: end\r?$

Related