Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Fill in Text with blanks.

I am completing a requirement for a bank upload of account transactions.
There is a requirement that the upload contain blanks to the right to fill a
required field. I am struggling to figure out how to do this.

Example:
If the field is 18 characters long and the entry is 10 characters long, then
they want the remaining characters expressed as blanks to the right.

So,

HowdyDoody would be "HowdyDoody "


Any ideas?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 360
Default Fill in Text with blanks.

Here's a way - evaluate the length of each entry, add blanks if less
than desired, then return the number of characters required.

Sub addBlanks()
Dim c As Range

For Each c In Sheet1.Range("a1:a5")
If Len(c.Text) < 18 Then
c.Offset(0, 1).Value = _
Left(c.Text & " ", 18)
End If
Next c

End Sub

Cliff Edwards
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Fill in Text with blanks.

Try something along the lines of

Dim S As String
S = "whatever"
If Len(S) = 18 Then
S = Left$(S, 18)
Else
S = S & Space$(18 - Len(S))
End If

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)




On Tue, 12 May 2009 12:11:01 -0700, David Langschied
wrote:

I am completing a requirement for a bank upload of account transactions.
There is a requirement that the upload contain blanks to the right to fill a
required field. I am struggling to figure out how to do this.

Example:
If the field is 18 characters long and the entry is 10 characters long, then
they want the remaining characters expressed as blanks to the right.

So,

HowdyDoody would be "HowdyDoody "


Any ideas?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Fill in Text with blanks.

If it is NEVER possible for the entry to be longer than 18 characters (that
is, will NEVER overflow the field), then...

FilledOutField = Format(TheEntry, "!" & String(18, "@"))

If it is possible for your entry to overflow the field, then it depends on
which part of the entry you want to keep. If that would be the last 18
characters, then use the above code. If that would be the first 18
characters, then use this instead....

FilledOutField = Format(Left(TheEntry, 18), "!" & String(18, "@"))

--
Rick (MVP - Excel)


"David Langschied" wrote in
message ...
I am completing a requirement for a bank upload of account transactions.
There is a requirement that the upload contain blanks to the right to fill
a
required field. I am struggling to figure out how to do this.

Example:
If the field is 18 characters long and the entry is 10 characters long,
then
they want the remaining characters expressed as blanks to the right.

So,

HowdyDoody would be "HowdyDoody "


Any ideas?


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Fill in Text with blanks.

Another possibility you can explore is fixed-length strings...

Dim FilledOutField As String * 18
......
......
FilledOutField = TheEntry

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
If it is NEVER possible for the entry to be longer than 18 characters
(that is, will NEVER overflow the field), then...

FilledOutField = Format(TheEntry, "!" & String(18, "@"))

If it is possible for your entry to overflow the field, then it depends on
which part of the entry you want to keep. If that would be the last 18
characters, then use the above code. If that would be the first 18
characters, then use this instead....

FilledOutField = Format(Left(TheEntry, 18), "!" & String(18, "@"))

--
Rick (MVP - Excel)


"David Langschied" wrote in
message ...
I am completing a requirement for a bank upload of account transactions.
There is a requirement that the upload contain blanks to the right to
fill a
required field. I am struggling to figure out how to do this.

Example:
If the field is 18 characters long and the entry is 10 characters long,
then
they want the remaining characters expressed as blanks to the right.

So,

HowdyDoody would be "HowdyDoody "


Any ideas?





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 947
Default Fill in Text with blanks.

David Langschied wrote:
I am completing a requirement for a bank upload of account transactions.
There is a requirement that the upload contain blanks to the right to fill a
required field. I am struggling to figure out how to do this.

Example:
If the field is 18 characters long and the entry is 10 characters long, then
they want the remaining characters expressed as blanks to the right.

So,

HowdyDoody would be "HowdyDoody "


Hi. Just an idea if one wanted spaces to the Left.

Sub Demo()
Dim s As String * 18
s = "OnLeft"
Debug.Print s & ":"

RSet s = "OnRight"
Debug.Print s & ":"
End Sub


OnLeft :
OnRight:

= = =
Dana DeLouis
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Fill in Text with blanks.

Thanks! This works perfectly!

"Rick Rothstein" wrote:

If it is NEVER possible for the entry to be longer than 18 characters (that
is, will NEVER overflow the field), then...

FilledOutField = Format(TheEntry, "!" & String(18, "@"))

If it is possible for your entry to overflow the field, then it depends on
which part of the entry you want to keep. If that would be the last 18
characters, then use the above code. If that would be the first 18
characters, then use this instead....

FilledOutField = Format(Left(TheEntry, 18), "!" & String(18, "@"))

--
Rick (MVP - Excel)


"David Langschied" wrote in
message ...
I am completing a requirement for a bank upload of account transactions.
There is a requirement that the upload contain blanks to the right to fill
a
required field. I am struggling to figure out how to do this.

Example:
If the field is 18 characters long and the entry is 10 characters long,
then
they want the remaining characters expressed as blanks to the right.

So,

HowdyDoody would be "HowdyDoody "


Any ideas?



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
Fill in the blanks! Bhupinder Rayat Excel Programming 2 March 2nd 06 04:47 PM
Fill in the blanks! Bhupinder Rayat Excel Programming 2 March 2nd 06 04:46 PM
Fill in the blanks!! Bhupinder Rayat Excel Programming 1 March 2nd 06 04:33 PM
Fill in the blanks BOB Excel Programming 1 January 31st 05 06:21 PM
Fill in the blanks Jim Thomlinson[_3_] Excel Programming 0 January 31st 05 06:16 PM


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