Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4
Default cell lenght MUST be always 30

eHello:

I need to always have 30 char in a given cell, if the original string is
less than 30 chars, lets say 23 then I need to fill in at the right of the
string with 7 blank spaces. The original string lenght may vary from 1 to 30.
Is there a formula or VBA code to do this?
Any and all help would be highly appreciated!

PLK
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 15,768
Default cell lenght MUST be always 30

The original string lenght may vary from 1 to 30.

Using a formula...

A1 = some string

B1 = formula:

=A1&REPT(" ",30-LEN(A1))

--
Biff
Microsoft Excel MVP


"JABAgdl" wrote in message
...
eHello:

I need to always have 30 char in a given cell, if the original string is
less than 30 chars, lets say 23 then I need to fill in at the right of the
string with 7 blank spaces. The original string lenght may vary from 1 to
30.
Is there a formula or VBA code to do this?
Any and all help would be highly appreciated!

PLK



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 806
Default cell lenght MUST be always 30

=LEFT(A1&REPT(" ",30),30)
covers also the case of A1 having more than 30 characters...

Regards,
Bernd
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default cell lenght MUST be always 30

--A formula applied in a cell can reference another cell text and format that
to 30 chars

=A1&REPT(" ",30-LEN(A1))

--VBA solution. Select the sheet tab which you want to work with. Right
click the sheet tab and click on 'View Code'. This will launch VBE. Paste the
below code to the right blank portion. Get back to to workbook and try out.


Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
If Target.Text < "" Then
Application.EnableEvents = False
Target.Value = Target.Value & Space(30 - Len(Target.Value))
Application.EnableEvents = True
End If
End If
End Sub


--
Jacob


"JABAgdl" wrote:

eHello:

I need to always have 30 char in a given cell, if the original string is
less than 30 chars, lets say 23 then I need to fill in at the right of the
string with 7 blank spaces. The original string lenght may vary from 1 to 30.
Is there a formula or VBA code to do this?
Any and all help would be highly appreciated!

PLK

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 22,906
Default cell lenght MUST be always 30

You don't say what you want if there are more than 30 characters in a cell.

Do you have to deal with that?

Or did you mean "at least" 30 characters?


Gord Dibben MS Excel MVP

On Thu, 18 Feb 2010 20:30:01 -0800, JABAgdl
wrote:

eHello:

I need to always have 30 char in a given cell, if the original string is
less than 30 chars, lets say 23 then I need to fill in at the right of the
string with 7 blank spaces. The original string lenght may vary from 1 to 30.
Is there a formula or VBA code to do this?
Any and all help would be highly appreciated!

PLK




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
Max Formula Lenght Milind Keer[_2_] Excel Discussion (Misc queries) 3 September 3rd 08 06:40 PM
fixed cell lenght Bob Excel Discussion (Misc queries) 1 August 19th 08 08:38 AM
Lenght of sheets Dupie1 Excel Worksheet Functions 2 March 18th 08 07:31 PM
lenght of status bar Chris Excel Discussion (Misc queries) 2 November 20th 06 11:36 AM
Calculating a sum of various lenght ASA Excel Worksheet Functions 3 July 13th 05 05:20 AM


All times are GMT +1. The time now is 01:18 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"