Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Fixed Length Text fields

Can anyone suggest how I can right pad a text field so that it always has a
fixed length of 18. I have an import requirement that a field is 18
characters long but the source data is variable length and unfortunately I
cannot use delimiters in the import.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Fixed Length Text fields

Hi Mervin,

I have created a common function:

Public Function RightPad(ByVal sOriginal As String, ByVal iLength As
Integer) As String
If Len(sOriginal) < iLength Then
RightPad = sOriginal & Space(iLength - Len(sOriginal))
Else
RightPad = Left(sOriginal, iLength)
End If
End Function

It takes 2 parameters:
1) The string
2) The length it must have.

If it is shorter some spaces will be added at the end.
If if is to long it will be truncated at the given length.

HTH.


Executor

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Fixed Length Text fields

That's perfect!
Mervyn
"Executor" wrote in message
oups.com...
Hi Mervin,

I have created a common function:

Public Function RightPad(ByVal sOriginal As String, ByVal iLength As
Integer) As String
If Len(sOriginal) < iLength Then
RightPad = sOriginal & Space(iLength - Len(sOriginal))
Else
RightPad = Left(sOriginal, iLength)
End If
End Function

It takes 2 parameters:
1) The string
2) The length it must have.

If it is shorter some spaces will be added at the end.
If if is to long it will be truncated at the given length.

HTH.


Executor



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
Text to column fixed length Luci Excel Discussion (Misc queries) 6 November 27th 08 06:27 PM
Advanced export/ Fixed length fields raws New Users to Excel 2 January 12th 06 02:38 PM
Create fields in a form with a fixed length sgeels Excel Discussion (Misc queries) 1 November 12th 05 05:11 AM
save an excel file in fixed length records whose fields are blank ascii save Excel Discussion (Misc queries) 1 October 13th 05 06:01 PM
Save data in a worksheet in fixed length fields... dietzd Excel Discussion (Misc queries) 1 January 26th 05 06:17 PM


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