Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Make the charecters in a cell to equal a certain quanity

Hi

I have a database in excel which holds information for a label program
to import & produce barcodes.

My problem is i need to have each cell to have the same amount of
charecters to keep consistency in the barcode image size, say 10
charecters.

So if i have a label holding the following infomation, ABCDEFG i need
to add 3 spaces to equal the 10 charecters.

Is it poosible to write a macro that counts the charecters and then
add the required amount of spaces to equal 10 charecters.

Thanks

Add
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,651
Default Make the charecters in a cell to equal a certain quanity

On Sat, 1 Dec 2007 08:37:27 -0800 (PST), Adam wrote:

Hi

I have a database in excel which holds information for a label program
to import & produce barcodes.

My problem is i need to have each cell to have the same amount of
charecters to keep consistency in the barcode image size, say 10
charecters.

So if i have a label holding the following infomation, ABCDEFG i need
to add 3 spaces to equal the 10 charecters.

Is it poosible to write a macro that counts the charecters and then
add the required amount of spaces to equal 10 charecters.

Thanks

Add


Simple formula:

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

and it will give an error if LEN(A1)NumChars

Or, as a macro:

======================================
Option Explicit
Sub Pad10()
Dim c As Range
For Each c In Selection
c.Value = c.Text & _
Application.WorksheetFunction.Rept(" ", 10 - Len(c.Text))
Next c
End Sub
=====================================
--ron
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default Make the charecters in a cell to equal a certain quanity

I have a database in excel which holds information for a label program
to import & produce barcodes.

My problem is i need to have each cell to have the same amount of
charecters to keep consistency in the barcode image size, say 10
charecters.

So if i have a label holding the following infomation, ABCDEFG i need
to add 3 spaces to equal the 10 charecters.

Is it poosible to write a macro that counts the charecters and then
add the required amount of spaces to equal 10 charecters.


Select the cells you want to add the spaces to and then run this macro...

Sub Make10CharsWide()
Dim Cel As Range
For Each Cel In Selection
Cel.Value = Format(Cel.Value, "!@@@@@@@@@@")
Next
End Sub

It will add the spaces to the end of the cell's text; if the cell's text is
longer than 10 characters, it will be truncated from the right side down to
10 characters. If you want to add the spaces to the left side, just remove
the exclamation point (!) from the Format function's pattern string;
however, for this condition, if your cell's text is longer than 10
characters, it will not be changed.

Rick

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
can I make cell "yes" equal 1, "no" equal 0 can I make cell yes equal 1, no equa Excel Discussion (Misc queries) 4 April 22nd 23 06:09 AM
Make a cell not equal less than a certain number Karl Davidson Excel Worksheet Functions 5 July 23rd 08 02:50 AM
can I make worksheet name equal a cell flyingdoc Excel Worksheet Functions 3 July 22nd 05 03:19 PM
How to make a cell equal text Adam Excel Programming 4 January 14th 05 11:23 AM
How do I make one cell equal to another Deb Blackshaw Excel Worksheet Functions 2 December 20th 04 12:29 AM


All times are GMT +1. The time now is 09:59 AM.

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"