Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Add spaces to end of field in save as PRN

Hi all,
I have a sheet that I need to save to space delimited(PRN). My dilemma
is how to add 12 spaces at the end of a six-character field.
The field is as follows

000123 and in the text file I need "000123 "
I know I can copy and paste into Access and then use the the Export
function and set the fixed-width parameters, but I would prefer to
find a way to do this in Excel.
Any suggestions greatly appreciated.
TIA,
Jim
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Add spaces to end of field in save as PRN

Jim,

Try the macro below.

HTH,
Bernie
MS Excel MVP

Sub ExportTo12WidthPRN()

Dim FName As String
Dim WholeLine As String
Dim FNum As Integer
Dim RowNdx As Long
Dim ColNdx As Integer
Dim StartRow As Long
Dim EndRow As Long
Dim StartCol As Integer
Dim EndCol As Integer

FName = Application.GetSaveAsFilename

Application.ScreenUpdating = False
On Error GoTo EndMacro:
FNum = FreeFile


With ActiveSheet.UsedRange
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With

Open FName For Output Access Write As #FNum

For RowNdx = StartRow To EndRow
WholeLine = ""
For ColNdx = StartCol To EndCol
WholeLine = WholeLine & _
Left(Cells(RowNdx, ColNdx).Text & _
Space(12), 12)
Next ColNdx
Print #FNum, WholeLine

Next RowNdx

EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #FNum

End Sub


"Jim" wrote in message
om...
Hi all,
I have a sheet that I need to save to space delimited(PRN). My

dilemma
is how to add 12 spaces at the end of a six-character field.
The field is as follows

000123 and in the text file I need "000123 "
I know I can copy and paste into Access and then use the the Export
function and set the fixed-width parameters, but I would prefer to
find a way to do this in Excel.
Any suggestions greatly appreciated.
TIA,
Jim



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Add spaces to end of field in save as PRN

Bernie,
Thanks I'll give this a try.
Jim

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message ...
Jim,

Try the macro below.

HTH,
Bernie
MS Excel MVP

Sub ExportTo12WidthPRN()

Dim FName As String
Dim WholeLine As String
Dim FNum As Integer
Dim RowNdx As Long
Dim ColNdx As Integer
Dim StartRow As Long
Dim EndRow As Long
Dim StartCol As Integer
Dim EndCol As Integer

FName = Application.GetSaveAsFilename

Application.ScreenUpdating = False
On Error GoTo EndMacro:
FNum = FreeFile


With ActiveSheet.UsedRange
StartRow = .Cells(1).Row
StartCol = .Cells(1).Column
EndRow = .Cells(.Cells.Count).Row
EndCol = .Cells(.Cells.Count).Column
End With

Open FName For Output Access Write As #FNum

For RowNdx = StartRow To EndRow
WholeLine = ""
For ColNdx = StartCol To EndCol
WholeLine = WholeLine & _
Left(Cells(RowNdx, ColNdx).Text & _
Space(12), 12)
Next ColNdx
Print #FNum, WholeLine

Next RowNdx

EndMacro:
On Error GoTo 0
Application.ScreenUpdating = True
Close #FNum

End Sub


"Jim" wrote in message
om...
Hi all,
I have a sheet that I need to save to space delimited(PRN). My

dilemma
is how to add 12 spaces at the end of a six-character field.
The field is as follows

000123 and in the text file I need "000123 "
I know I can copy and paste into Access and then use the the Export
function and set the fixed-width parameters, but I would prefer to
find a way to do this in Excel.
Any suggestions greatly appreciated.
TIA,
Jim

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
Replace spaces at the end of a field Colin3440 Excel Discussion (Misc queries) 1 March 3rd 10 01:24 PM
Save as CSV: extra spaces around commas rjml Excel Discussion (Misc queries) 2 March 3rd 09 05:59 PM
How do I put spaces in a field Stan in South Africa Excel Discussion (Misc queries) 2 July 8th 08 09:12 AM
How do you remove excess spaces from an Excel field? sarah_jane Excel Discussion (Misc queries) 1 June 1st 05 08:15 AM
Adding spaces to a text field Jason Trolian Excel Programming 2 December 1st 03 04:26 PM


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