Space Function for Worksheet Functions

T

tig

Is there a way to use the VB Space(function) in a cell? The number of
spaces that I need in each cell can vary.

Any ideas??

TIA
 
B

Ben

Try this function

Function Space(Number As Integer)

Dim x As Integer

Space = ""
For x = 1 To Number
Space = Space & " "
Next x

End Function

Then you can use formula like this ="t"&space(C2)&"R" where c2 has an
integer like "7" in it to return "t R".

Ben
 
K

komeatshield

In case you're not necessarily looking for a VBA solution, you can use
the REPT function in excel to mimic the code that Ben posted without
having to use VBA.
Just enter the formula
=REPT(" ",5) and you'll get 5 spaces
If you use something like ="t"&rept(" ",C2)&"R" when C2 has an integer
(like 7) in it, you'll return "t R" just as Ben would with the
Space function.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top