![]() ' xlHAlignFill - Fills the specified length with the text ' xlHAlignJustify - Same as xlHAlignDistributed ' xlHAlignDistributed - Distributes the text evenly within the length specified ![]() ' xlHAlignCenterAcrossSelection - Same as xlHAlignCenter ' xlHAlignRight - Aligns input text to the right ' xlHAlignLeft - (Default) Aligns input text to the left 'Pads a string with a given - the string to - the minimum length of the string (if is longer than the original Expression will be - the character to pad with (a space by - what type of alignment to use. ![]() Here is the function: Function PadStr(Expression As Variant, length As Integer, Optional padChar As String = " ", Optional alignment As XlHAlign = xlHAlignGeneral) As String Here are several examples on how to use the function: Sub test()ĭebug.Print PadStr("ABC", 6) 'returns "ABC "ĭebug.Print PadStr("ABC", 6, "-") 'returns "ABC-"ĭebug.Print PadStr("ABC", 6,, xlHAlignRight) 'returns " ABC"ĭebug.Print PadStr("ABC", 7, "*", xlHAlignCenter) 'returns "**ABC**"ĭebug.Print PadStr("ABC", 9, "*", xlHAlignDistributed) 'returns "**A**B*C*"ĭebug.Print PadStr("ABC", 7, "*", xlHAlignFill) 'returns "ABCABCA" ![]() I used some of the code from LittleBobbyTables and Brad to produce this. Its not the most simple one, but its probably the most general. I took a different approach for this answer. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |