#1   Report Post  
Posted to microsoft.public.excel.programming
Tom Tom is offline
external usenet poster
 
Posts: 25
Default Add space.

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Add space.

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Add space.

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   Report Post  
Posted to microsoft.public.excel.programming
Tom Tom is offline
external usenet poster
 
Posts: 25
Default Add space.

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Space-bar -- "recurring" instead of <space CRW Excel Discussion (Misc queries) 1 May 2nd 09 05:46 AM
Space removal - a first name,space last name Tech Express Excel Discussion (Misc queries) 4 February 9th 09 08:24 PM
Can I automatically add space after ea. row ("Space After" in Word Reddheddz Excel Discussion (Misc queries) 0 June 17th 08 05:55 PM
formula that will go up one space if no value in specified space skammi Excel Worksheet Functions 1 November 16th 05 03:28 PM
Paper Space / Model Space ? Coolboy55 Excel Discussion (Misc queries) 0 September 1st 05 08:58 PM


All times are GMT +1. The time now is 01:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"