Visual Basic for Applications/Listing Prime Numbers

Summary
. 'This module implements the Sieve of Eratosthenes'' method for the listing of prime numbers. It is made to run in Microsoft Excel as a standard VBA module. It lists the prime numbers found between unity and some parameter integer value, on Sheet1 of the Workbook, and makes use of a message box for short listings'''.
 * Overflow is a problem for such procedures, but provided that the input parameter is kept within a few millions or so, overflow is unlikely.
 * The method although simple is quite slow, since even to test one single value, the entire sequence of multiples (2,3,5,7,...n) must be completed.  Large values of input will take several minutes to complete. A faster approach is to test only those factors  that are smaller than the square root of the input value; this modification is used in the procedure GetPrimeFactors.
 * Note that the procedure will clear any contents of Sheet1 before each listing.
 * An animated GIF found in Wiki Commons is included in Figure 1 to illustrate the method.
 * GetPrimeFactors and its utility DecMod list the prime factors of a supplied integer.  It is written for the decimal subtype, and so it handles inputs of up to 28 full digits, (assuming all nines).   The time to complete varies greatly, depending on how many primes are found.   There is one peculiarity noted; for example, with an input of 23 nines the answer takes a very long time, but for 28 nines it takes just fifteen seconds or so.   Other values like 20, 21, and 22 nines, and so on, are virtually instantaneous.  The use of a string for input in the test procedure testGetPrimeFactors is simply to prevent Excel from truncating the displayed input integer, and has no bearing on the method used; it is not string math here; just a decimal subtype loop.