ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Fill in Text with blanks. (https://www.excelbanter.com/excel-programming/428379-fill-text-blanks.html)

David Langschied

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?


ward376

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

Chip Pearson

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?


Rick Rothstein

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?



Rick Rothstein

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?




Dana DeLouis

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

David Langschied

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?





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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com