Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hello,
I have strings: my1 = "test" my2 ="something" and I need algoritmus for adding so many spaces, to resultant lenght of my string will be for example 20, so: result = (my1 + 16 space) or result = (my2 + 11 space) some idea? I came upon only a long solution. tom |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
result = left(my1 & space(20),20)
might work ok Tom wrote: Hello, I have strings: my1 = "test" my2 ="something" and I need algoritmus for adding so many spaces, to resultant lenght of my string will be for example 20, so: result = (my1 + 16 space) or result = (my2 + 11 space) some idea? I came upon only a long solution. tom -- Dave Peterson |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Tom,
The code below will do what you want. This is attached to a command button, which takes the text in cell A1, tests its length, then adds the appropriate number of space, and then puts the results in cell A2, you can of course do whatever you like with the result. I haven't tested to see what happens if you put a string in of more than 20 characters, so you might want to do that or add some validation. Range("A1").Select 'Select Cell A1 mystring$ = ActiveCell 'Copy contents of A1 to variable mystring$ a = Len(mystring$) ' Get length of mystring$ and put contents into a b = 20 - a 'subtract length of mystring$ from 20 For x = 1 To b 'loops number of times defined by b mystring$ = mystring$ + " " 'adds a space to end of mystring$ Next x 'Test it worked Range("A2").Select 'Select Cell A2 ActiveCell = mystring$ 'Paste new mystring$ into A2 Hope this is of use and makes sense to you, if not please post again and I will see if I can make it better for you. Neil www.nwarwick.co.uk "Tom" wrote: Hello, I have strings: my1 = "test" my2 ="something" and I need algoritmus for adding so many spaces, to resultant lenght of my string will be for example 20, so: result = (my1 + 16 space) or result = (my2 + 11 space) some idea? I came upon only a long solution. tom |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
perfect thanks
"Dave Peterson" wrote in message ... result = left(my1 & space(20),20) might work ok Tom wrote: Hello, I have strings: my1 = "test" my2 ="something" and I need algoritmus for adding so many spaces, to resultant lenght of my string will be for example 20, so: result = (my1 + 16 space) or result = (my2 + 11 space) some idea? I came upon only a long solution. tom -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Space-bar -- "recurring" instead of <space | Excel Discussion (Misc queries) | |||
Space removal - a first name,space last name | Excel Discussion (Misc queries) | |||
Can I automatically add space after ea. row ("Space After" in Word | Excel Discussion (Misc queries) | |||
formula that will go up one space if no value in specified space | Excel Worksheet Functions | |||
Paper Space / Model Space ? | Excel Discussion (Misc queries) |