Home |
Search |
Today's Posts |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Right justify a string
"Robert Crandal" wrote previously:
Suppose I have the following string variables: s1 = "0000" s2 = "13" I would like to copy the contents of s2 and insert it into s1 in a right justified manner. So, the final result of s1 would be: s1 = "0013" "Robert Crandal" wrote I overlooked a few situations. Suppose that the s1 variable contains 4 space character (or ANY characters, for that matter): s1 = " " ' string with 4 spaces s2 = "13" Now, I would want s1 to look like: s1 = " 13" Generally: s1 = Left(s1,Len(s1)-Len(s2)) & s2 or s1 = IIf(Len(s1)<Len(s2),s2,Left(s1,Len(s1)-Len(s2)) & s2) But you might not need to "preload" s1 at all, if that is what you are doing. Suppose n is the total length. Then: s1 = String(n - Len(s2),fillCharacter) & s2 |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Justify across selection | Excel Worksheet Functions | |||
Justify distributed? | Excel Discussion (Misc queries) | |||
Justify? | Excel Discussion (Misc queries) | |||
Excel Justify | Excel Programming | |||
Series & Justify? | New Users to Excel |