Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 158
Default String centering

Suppose I have the following string:

s = "iPhone" ' string length is 6

I want to modify the above string variable such that
the string length is 20, AND, the string is centered or
padded with spaces.

The result should look like:

s = " iPhone " ' string length is 20

Does that make sense? I just want to transform a
string variable so it is padded with space characters
and it appears (somewhat) centered. I prefer
a general solution for situations where I want to
center the string within a string length of N characters.

Thanks!




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default String centering

Hi Robert,

Am Tue, 5 Mar 2013 03:00:04 -0700 schrieb Robert Crandal:

s = "iPhone" ' string length is 6

I want to modify the above string variable such that
the string length is 20, AND, the string is centered or
padded with spaces.

The result should look like:

s = " iPhone " ' string length is 20


center your strings with Home tab = Alignment.
If you center your strings with spaces it is hard to find them with
MATCH and other functions.
If you still want do it, look the REPT function


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,045
Default String centering

On Tue, 5 Mar 2013 03:00:04 -0700, "Robert Crandal" wrote:

Suppose I have the following string:

s = "iPhone" ' string length is 6

I want to modify the above string variable such that
the string length is 20, AND, the string is centered or
padded with spaces.

The result should look like:

s = " iPhone " ' string length is 20

Does that make sense? I just want to transform a
string variable so it is padded with space characters
and it appears (somewhat) centered. I prefer
a general solution for situations where I want to
center the string within a string length of N characters.

Thanks!




Try this:

Dim s As String * 20
s = Space((20 - Len(Trim(teststring))) \ 2) & Trim(teststring) & Space(20)

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
text centering AlanW Excel Programming 1 September 1st 07 08:22 AM
Centering Centering a Title New Users to Excel 6 December 13th 06 10:02 PM
Centering comments flyingrhino Excel Worksheet Functions 0 April 11th 06 07:25 AM
Centering columns bbc920 Excel Discussion (Misc queries) 1 July 22nd 05 04:25 AM
Centering Toolbars James L[_3_] Excel Programming 1 April 14th 04 02:37 PM


All times are GMT +1. The time now is 11:08 AM.

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

About Us

"It's about Microsoft Excel"