Written by Allen Wyatt (last updated September 22, 2023)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and 2021
If you have done any programming in VBA, you know the value of using variable arrays to store information. It is not uncommon to start working with large arrays in your macros. For instance, you might declare a 100-element string array, as follows:
Dim MyText(99) As String
As your macro executes, information can be stored and restored in the elements of the array. At some time, you may want to erase all the information in the array. One classic way of doing this is using a For ... Next loop to step through each array element, as follows:
For J = 0 To 99 MyText(J) = "" Next J
When the looping is complete, everything has been erased from the array. A quicker way of accomplishing the same task is to use the ERASE function, as follows:
Erase MyText
Once executed, this single line sets each element of the MyText array back to an empty string. If the array is numeric, then each element of the array is set to zero.
Note:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (676) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and 2021. You can find a version of this tip for the older menu interface of Word here: Quickly Clearing Array Contents.
Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!
When writing a macro, you may need a way to clear the undo stack. This can be done with a single command, as described in ...
Discover MoreNeed to have your macro insert a bit of text into your document? It's easy to do using the TypeText method.
Discover MoreWhen writing a macro to process the text in a document, you may need to move the insertion point to the end of a line. ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2021-01-04 14:41:14
Nickie Geldenhuys
Is it possible to create a macro that will do several processes, like "find all sentences beginning with 'And' eliminate that unnecessary conjunction then capitalize the next word, regardless of what that word will be?
2019-08-16 01:05:37
Muhammad Ashfaq
Sir, i want to use thousand separator e.g. 10000000 wants write as 1,00,00,000. thanks while using mail merge tool
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2025 Sharon Parq Associates, Inc.
Comments