SSource = sSource & "abcdefghijklmnopqrstuvwxyz" If you would rather use a macro, then you can easily create a user-defined function that will return a random-character string of any length you desire:įunction RandChars(iLen As Integer) As String The result is a random text string, just the length you want. (Actually, you could put any other length in A2, but Richard specifically needed 15- and 20-character strings.) Now, use the following formula: So, in cell A2 place either 15 or 20, depending on the length of string you want to generate. You already have your base characters in cell A1. You can, instead, use the powerful RANDARRAY function combined with the CONCAT function. Fortunately, if you are using the version of Excel provided with Microsoft 365, you don't need to rely on super-long formulas to generate the strings you want. This can (obviously) lead to some very long formulas. If you want to return 15 characters, then you just need to use 15 iterations of the core formula: For instance, the following will return 2 characters: Now, to lengthen what is returned, you just need to start combining this core formula using the ampersand character. This uses the MID and RANDBETWEEN functions to select a single random character from whatever characters you placed in cell A1. For instance, you could put the following 62 characters in A1:ĪBCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 Start by putting into cell A1 all the possible characters that you may want included in your strings. He knows about the RANDBETWEEN function, but doesn't really see how it could be helpful for his purposes.Īctually, you can use the RANDBETWEEN function as the core of your formula. The strings can contain letters and digits, with no spaces. Richard has a need to generate random 15- and 20-character strings, and he thought he might be able to do it in Excel.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |