Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
can I make cell "yes" equal 1, "no" equal 0 | Excel Discussion (Misc queries) | |||
Make a cell not equal less than a certain number | Excel Worksheet Functions | |||
can I make worksheet name equal a cell | Excel Worksheet Functions | |||
How to make a cell equal text | Excel Programming | |||
How do I make one cell equal to another | Excel Worksheet Functions |