Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default How do I autofill spaces in right justified fields?

I've set up fixed length fields. My data is right justified. I want to be
able to save to a text file and retain the data with fixed length fields,
with leading spaces to pad the right justified data so everything lines up
the way I entered it.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 20
Default How do I autofill spaces in right justified fields?

On Jul 17, 10:40*pm, Bob_Balch
wrote:
I've set up fixed length fields. *My data is right justified. *I want to be
able to save to a text file and retain the data with fixed length fields,
with leading spaces to pad the right justified data so everything lines up
the way I entered it.


couldn't find a way to have excel format it, so here are some
solutions I came up with.
in the following, you would still need to decide what to do when the
contents are longer than the fixed width specified... i'll leave that
up to you.
(1) could have a worksheet that references the other and adds the
padding via formulas. Then save that sheet as the text file.
=REPT(" ", $A$1 - LEN(Sheet1!A2)) & Sheet1!A2
$A$1 is the fixed width

(2) vba routine to sweep a specified sheet and make each cell fixed
width

Sub processSheets()
Const FIXED_WIDTH As Long = 10
Dim sh As Worksheet

'could loop for all sheets
Set sh = ActiveSheet
applyFixedWidth FIXED_WIDTH, sh

End Sub

Sub applyFixedWidth(fixedWidth As Integer, sh As Worksheet)

Dim rng As Range
Dim elem As Range
Dim length As Long

If (fixedWidth < 0) Then Exit Sub

For Each elem In sh.UsedRange
length = Len(elem.Value)
If (length < fixedWidth) Then
elem.Value = Space(fixedWidth - length) + elem.Value
Else
'???
End If
Next

End Sub
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
Dollar sign left justified - data right justified - large space BuzzRogers Excel Discussion (Misc queries) 4 April 4th 23 11:27 AM
Custom Fields with spaces [email protected] Excel Discussion (Misc queries) 15 July 16th 07 10:09 AM
by default text is left justified, numbers are right justified - a specific reason for this? showsomeidnow Excel Discussion (Misc queries) 2 April 30th 07 08:43 PM
rows top-justified & bottom-justified in same sheet looks bad Jim 007 Excel Worksheet Functions 2 March 8th 06 10:56 PM
Add spaces for specific fields to paste in Corey Excel Discussion (Misc queries) 3 December 30th 05 10:22 PM


All times are GMT +1. The time now is 05:24 PM.

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"